标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6247 | Accepted: 1601 |
Description
Input
Output
Sample Input
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output
1 3 2
错了N次。。这个题坑点在于只能是五子棋,6子,7子都不行,所以对一个点的某一个方向来说正反都要搜一遍。
而且还要注意是结果是要位于左上角的点。所以可以先将某一列的每一行先找一遍,这样的话得到的结果就一定是左上角的点。
给大家两组测试用例:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0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0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
答案是
1
6 1
#include<cstdio> #include<cstring> #include<algorithm> #include<math.h> #include<queue> #include<iostream> using namespace std; typedef long long LL; int graph[20][20]; bool vis[20][20]; int cnt; int res,resx,resy; int dir[][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{-1,1},{1,-1}}; bool check(int x,int y,int flag) { if(x<1||x>19||y<1||y>19||graph[x][y]!=flag) return false; return true; } struct Node { int x,y; int step; }; Node s; bool bfs(int x,int y,int flag) { Node now; now.x = x,now.y = y,now.step = 0; Node next; for(int i=0; i<8; i++) { next.x = now.x+dir[i][0]; next.y = now.y +dir[i][1]; next.step = now.step+1; while(check(next.x,next.y,flag)) { next.x+=dir[i][0]; next.y+=dir[i][1]; next.step++; } int step1 = next.step - 1; next.x = now.x+dir[i^1][0]; ///反方向也要找 next.y = now.y +dir[i^1][1]; next.step = now.step+1; while(check(next.x,next.y,flag)) { next.x+=dir[i^1][0]; next.y+=dir[i^1][1]; next.step++; } int step2 = next.step - 1; if(step1+step2==4) return true; } return false; } int main() { int tcase; scanf("%d",&tcase); while(tcase--) { for(int i=1; i<20; i++) { for(int j=1; j<20; j++) { scanf("%d",&graph[i][j]); } } bool flag = false; res = 0,resx=-1,resy=-1; for(int j=1; j<20&&!flag; j++) { for(int i=1; i<20&&!flag; i++) { if(graph[i][j]==1) { flag = bfs(i,j,1); if(flag) { res = 1; resx = i; resy = j; } } if(graph[i][j]==2) { flag = bfs(i,j,2); if(flag) { res = 2; resx = i; resy = j; } } } } if(res==0) printf("0\n"); else printf("%d\n%d %d\n",res,resx,resy); } return 0; }
标签:
原文地址:http://www.cnblogs.com/liyinggang/p/5574518.html