| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
天啊!!!!一样的代码1562AC 2386WA 疯了!!!把应该去的注释去了,把WATER 和LAND 的值一改~! 1562就可以AC了!
这题却WA~~~~ 妈的~~~~
#include "stdio.h"
#include <queue>
char map[110][110];
struct _node
{
int i,j;
};
std::queue<_node> que;
int main()
{
int c,r,i,j;
char water='W',land='.';
char ch;
_node temp,node;
// freopen("c:\\acm\\data.txt","r",stdin);
// while(1){
scanf("%d%d",&r,&c);
// if(r==0) break;
//scanf("\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
while((ch=getchar())&&(ch!=water&&ch!=land));
map[i][j]=ch;
}
//scanf("\n");
}
int count=0;
while(1)
{
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(map[i][j]==water)
break;
}
if(j!=c)
break;
}
if(j==c&&i==r)
break;
else
count++;
while(que.size()!=0) que.pop();
temp.i=i;
temp.j=j;
map[i][j]=land;
que.push(temp);
while(que.size()!=0)
{
temp=que.front();
que.pop();
//12
if(temp.i>0&&map[temp.i-1][temp.j]==water)
{
node.i=temp.i-1;
node.j=temp.j;
map[node.i][node.j]=land;
que.push(node);
}
//1.5
if(temp.i>0&&j<c-1&&map[temp.i-1][temp.j+1]==water)
{
node.i=temp.i-1;
node.j=temp.j+1;
map[node.i][node.j]=land;
que.push(node);
}
//3
if(temp.j<c-1&&map[temp.i][temp.j+1]==water)
{
node.i=temp.i;
node.j=temp.j+1;
map[node.i][node.j]=land;
que.push(node);
}
//4.5
if(temp.i<r-1&&temp.j<c-1&&map[temp.i+1][temp.j+1]==water)
{
node.i=temp.i+1;
node.j=temp.j+1;
map[node.i][node.j]=land;
que.push(node);
}
//6
if(temp.i<r-1&&map[temp.i+1][temp.j]==water)
{
node.i=temp.i+1;
node.j=temp.j;
map[node.i][node.j]=land;
que.push(node);
}
//7.5
if(temp.i<r-1&&j>0&&map[temp.i+1][temp.j-1]==water)
{
node.i=temp.i+1;
node.j=temp.j-1;
map[node.i][node.j]=land;
que.push(node);
}
//9
if(temp.j>0&&map[temp.i][temp.j-1]==water)
{
node.i=temp.i;
node.j=temp.j-1;
map[node.i][node.j]=land;
que.push(node);
}
//10.5
if(temp.i>0&&temp.j>0&&map[temp.i-1][temp.j-1]==water)
{
node.i=temp.i-1;
node.j=temp.j-1;
map[node.i][node.j]=land;
que.push(node);
}
}
}
printf("%d\n",count);//}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator