背景:一直wa!wa!我以为思路已经绝不会错了!结果还是wa!和别人代码比了半天都找不出来错误之处!
思路:简单的暴力,简单的数学。
学习:1.即使已经得到结果了,但还是应该继续输入,因为,输入流还有很多数据,不继续就会对下一次造成干扰!!但是!!既然后面输入的数据已经没有用了,那就不能让他对答案进行更新了!
#include<stdio.h>
#include<string.h>
int map[2000][2000];
int n,m,t,count;
bool make(int x,int y){
if(map[x][y] == 1) return false;
map[x][y]=1;
if(map[x-1][y-1] && map[x-1][y] && map[x][y-1]) return true;
if(map[x-1][y] && map[x-1][y+1] && map[x][y+1]) return true;
if(map[x][y+1] && map[x+1][y] && map[x+1][y+1]) return true;
if(map[x][y-1] && map[x+1][y-1] && map[x+1][y]) return true;
return false;
}
int main(void){
while(~scanf("%d%d%d",&n,&m,&t)){
int tt=6666,ans=0,x,y;
count=0;
memset(map,0,sizeof(map));
while(t--){
scanf("%d%d",&x,&y);
count++;
if(make(x,y) && !ans){
ans=count;
tt=-2333;
}
}
if(tt != -2333) printf("0\n");
else printf("%d\n",ans);
}
return 0;
}
原文地址:http://blog.csdn.net/jibancanyang/article/details/43230013