Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int dir[9][2]={{0,1},{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{-1,1},{1,-1}};
  5.  
  6. struct node{
  7. ​int x,y,cnt = 0;
  8. }beg;
  9.  
  10.  
  11. enum
  12. {
  13. ​EMPTY, //0
  14. ​BLACK, //1
  15. ​WHITE //2
  16. };
  17.  
  18. #define ROWS 19
  19. #define COLS ROWS
  20.  
  21. char chess[ROWS][COLS];
  22. char mp[ROWS][COLS];
  23. int vis[ROWS][COLS];
  24.  
  25. enum
  26. {
  27. ​BLACK_WIN, //0
  28. ​WHITE_WIN, //1​
  29. ​GO_ON //2
  30. };
  31.  
  32. int dfs(int role)
  33. {
  34. ​int len=0;
  35. ​for(int y=1;y<=ROWS;y++)
  36. ​{
  37. ​for(int x=1;x<=COLS;x++)
  38. ​{
  39. ​if(chess[y][x]==role)
  40. ​{
  41. ​for(int k=0;k<8;k++)
  42. ​{
  43. ​int ny=y;
  44. ​int nx=x;
  45. ​int h;
  46. ​for(h=0;h<5;h++)
  47. ​{
  48. ​if(chess[ny][nx]!=role)
  49. ​break;
  50. ​nx+=dir[k][1];
  51. ​ny+=dir[k][0];
  52. ​}
  53. ​len=max(h,len);
  54. ​}
  55. ​}
  56. ​}
  57. ​}
  58. ​return len;
  59. }
  60.  
  61. int dfs_changlian(int x,int y,int role){
  62. ​int len=0,flag = 1;;
  63. ​for(int k=0;k<8;k++)
  64. ​{
  65. ​int ny=y;
  66. ​int nx=x;
  67. ​int h;
  68. ​int cnt = 1,cntmax = 1;
  69. ​while(1)
  70. ​{​
  71. ​if(chess[ny][nx]!=role){
  72. ​if(chess[ny+dir[k][0]][nx+dir[k][1]] != role){
  73. ​break;
  74. ​}
  75. ​}
  76. ​nx+=dir[k][1];
  77. ​ny+=dir[k][0];
  78. ​cnt++;
  79. ​}
  80. ​cntmax = max(cnt ,cntmax);
  81. ​if(cntmax >= 6)​return 1;
  82. ​}
  83. ​return 0;
  84. }
  85. int ban44(int x,int y){
  86. }
  87.  
  88.  
  89. int ban33(int x,int y){
  90. ​//33
  91. ​int num3 = 0;
  92.  
  93. ​int cnt = 1;
  94. ​int cnt1 = 0;
  95. ​int pe=0;
  96. ​for(int i = 1;i <= 4;i ++){
  97. ​int tx = x-i;
  98. ​if(tx < 0 || tx > 19)continue;
  99. ​if(chess[tx][y] == 1) cnt++;
  100. ​else if(chess[tx][y] == 2) break;
  101. ​else {
  102. ​if(pe!=1){
  103. ​pe++;
  104. ​}
  105. ​else{
  106. ​pe++;
  107. ​break;
  108. ​}
  109. ​}
  110. ​}
  111. ​if(pe)cnt1++;
  112. ​pe=0;
  113. ​for(int i = 1;i <= 4; i++){
  114. ​int tx=x+i;
  115. ​if(tx > 19 || tx < 0)continue;
  116. ​if(chess[tx][y]==1) cnt++;
  117. ​else if(chess[tx][y]==2)break;
  118. ​else {
  119. ​if(pe!=1){
  120. ​pe++;
  121. ​}
  122. ​else {
  123. pe++;
  124. break;
  125. ​}
  126. ​}
  127. ​}
  128. ​if(pe)cnt1++;
  129. ​if(cnt >= 3 && cnt1 == 2)num3++;
  130. ​cnt=1;cnt1=0;pe=0;
  131. ​for(int i=1;i<=4;i++){
  132. ​int tx=x-i;
  133. ​int ty=y-i;
  134. ​if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
  135. ​if(chess[tx][ty]==1)cnt++;
  136. ​else if(chess[tx][ty]==2)break;
  137. ​else {
  138. ​if(pe!=1){
  139. ​pe++;
  140. ​}
  141. ​else {
  142. pe++;
  143. break;
  144. ​}
  145. }
  146. ​}
  147. ​if(pe)cnt1++;
  148. ​pe=0;
  149. ​for(int i=1;i<=4;i++){
  150. ​int tx=x+i;
  151. ​int ty=y+i;
  152. ​if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
  153. ​if(chess[tx][ty]==1) cnt++;
  154. ​else if(chess[tx][ty]==2) break;
  155. ​else {
  156. ​if(pe!=1)pe++;
  157. ​else {
  158. pe++;
  159. break;
  160. ​}
  161. ​}
  162. ​}
  163. ​if(pe)cnt1++;
  164. ​pe=0;
  165. ​if(cnt >= 3&& cnt1==2) num3++;
  166. ​cnt=1;cnt1=0;
  167. ​for(int i=1;i<=4;i++){
  168. ​int tx=x-i;
  169. ​int ty=y+i;
  170. ​if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
  171. ​if(chess[tx][ty]==1) cnt++;
  172. ​else if(chess[tx][ty]==2) break;
  173. ​else {
  174. ​if(pe!=1)pe++;
  175. ​else {
  176. pe++;
  177. break;
  178. ​}
  179. ​}
  180. ​}
  181. ​if(pe)cnt1++;
  182. ​pe=0;
  183. ​for(int i=1;i<=4;i++){
  184. ​int tx=x+i;
  185. ​int ty=y-i;
  186. ​if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
  187. ​if(chess[tx][ty]==1) cnt++;
  188. ​else if(chess[tx][ty]==2) break;
  189. ​else {
  190. ​if(pe!=1){
  191. ​pe++;
  192. ​}
  193. ​else {
  194. pe++;
  195. break;
  196. ​}
  197. ​}
  198. ​}
  199. ​if(pe)cnt1++;
  200. ​pe=0;
  201. ​if(cnt>=3&&cnt1==2)num3++;
  202. ​cnt1=0;cnt=1;
  203. ​for(int i=1;i<=4;i++){
  204. ​int ty=y-i;
  205. ​if(ty> 19|| ty < 0)continue;
  206. ​if(chess[x][ty]==1) cnt++;
  207. ​else if(chess[x][ty]==2) break;
  208. ​else {
  209. ​if(pe!=1){
  210. ​pe++;
  211. ​}
  212. ​else {
  213. pe++;
  214. break;
  215. ​}
  216. ​}
  217. ​}
  218. ​if(pe)cnt1++;
  219. ​pe=0;
  220. ​for(int i=1;i<=4;i++){
  221. ​int ty=y-i;
  222. ​if(ty> 19|| ty < 0)continue;
  223. ​if(chess[x][ty]==1) cnt++;
  224. ​else if(chess[x][ty]==2) break;
  225. ​else {
  226. ​if(pe!=1){
  227. ​pe++;
  228. ​}
  229. ​else {
  230. pe++;
  231. break;
  232. ​}
  233. ​}
  234. ​}
  235. ​if(pe)cnt1++;
  236. ​pe=0;
  237. ​if(cnt>=3&&cnt1==2)num3++;
  238. ​if(num3>=1){
  239. ​return 1;
  240. ​}
  241. ​else return 0;
  242. }
  243.  
  244.  
  245. int putChess(int role, int row, int col)
  246. {
  247.  
  248. ​chess[row][col] = role;
  249. ​int flag1 = dfs(role);
  250. ​if(flag1 >= 5){
  251. ​if(role == 2)​return WHITE_WIN;
  252. ​else ​return BLACK_WIN;
  253. ​}
  254. ​else{
  255. ​if(role == 1){
  256. ​int flag2 = ban33(row,col);
  257. ​int flag3 = ban44(row,col);
  258. ​int flag4 = dfs_changlian(row,col,role);
  259. ​if(!flag2&&!flag3&&!flag4){
  260. ​return GO_ON;
  261. ​}
  262. ​else return WHITE_WIN;
  263. ​}
  264. ​}​
  265. return GO_ON;
  266. }
  267.  
  268. int main()
  269. {
  270. ​freopen(”15.txt“,”r“,stdin);
  271. ​freopen(”out.txt“,”w“,stdout);
  272. char line[20];
  273. char *str = NULL;
  274. int ret = GO_ON;
  275. do {
  276. str = fgets(line, 20, stdin);
  277. ​if(str == NULL)break;
  278. int role, row, col;
  279. sscanf(line, ”%d %d %d“, &role, &row, &col);
  280. ret = putChess(role, row-1, col-1); ​
  281. ​} while(ret == GO_ON);
  282.  
  283. if(ret == BLACK_WIN)
  284. printf(”black win“);
  285. else if(ret == WHITE_WIN)
  286. printf(”white win“);
  287. ​else
  288. ​printf(”not end“);
  289.  
  290. return 0;
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement