| ||||||||||
| 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 | |||||||||
原来注释过多会出现RE的.....原来注释过多会出现RE的.....一定要注意啊。。。呃,我也是右一个7K多的。。。。纯模拟每一步。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int x,y,x1,y1,x3,y3,x2,y2,l1,l2,l3;
int map[100][100];
int num1,num2;
struct B
{
int x;
int y;
int pre;
}sq[10000];
int head,tail,p,q,k;
int fx[4]={-1,1,0,0};
int fy[4]={0,0,-1,1,};
int check(int i,int j)
{
if(map[i][j]==0) return 1;
return 0;
}
void dfs()
{ if(y1==y2&&x1==x2) return ;
// if(l1==37) {printf(" %d %d ",y1,x1);scanf("%d",&x);}
//scanf("%d",&x);
if(num1==0)
{
if(check(y1+1,x1)==1)
{ //printf("%d ",y1);scanf("%d",&x);
y1=y1+1;x1=x1;
num1=3;
l1++;
dfs();
}
else if(check(y1,x1-1)==1)
{ y1=y1;x1=x1-1;
num1=0;
l1++;//printf("%d %d %d ",y1,x1,l1);
dfs();
}
else if(check(y1-1,x1)==1)
{ // scanf("%d",&x);
y1=y1-1;x1=x1;
num1=1;
l1++; //printf("%d %d %d ",y1,num1,l1);
dfs();
}
else if(check(y1,x1+1)==1)
{ y1=y1;x1=x1+1;
num1=2;
l1++;
dfs();
}
}
else if(num1==1)
{
if(check(y1,x1-1)==1)
{ y1=y1;x1=x1-1;
num1=0;
l1++;
dfs();
}
else if(check(y1-1,x1)==1)
{
y1=y1-1;x1=x1;
num1=1;
l1++; //printf(" %d %d %d ",y1,x1,l1);
dfs();
}
else if(check(y1,x1+1)==1)
{ y1=y1;x1=x1+1;
num1=2;
l1++;//printf(" %d %d %d",y1,x1,l1);
dfs();
}
else if(check(y1+1,x1)==1)
{ y1=y1+1;x1=x1;
num1=3;
l1++;
dfs();
}
}
else if(num1==2)
{
if(check(y1-1,x1)==1)
{
y1=y1-1;x1=x1;
num1=1;
l1++;
dfs();
}
else if(check(y1,x1+1)==1)
{ y1=y1;x1=x1+1;
num1=2;
l1++;//printf(" %d %d %d",y1,x1,l1);
dfs();
}
else if(check(y1+1,x1)==1)
{ y1=y1+1;x1=x1;
num1=3;
l1++;//printf(" %d %d %d",y1,x1,l1);
dfs();
}
else if(check(y1,x1-1)==1)
{ y1=y1;x1=x1-1;
num1=0;
l1++;
dfs();
}
}
else if(num1==3)
{
if(check(y1,x1+1)==1)
{ y1=y1;x1=x1+1;
num1=2;
l1++;
dfs();
}
else if(check(y1+1,x1)==1)
{ y1=y1+1;x1=x1;
num1=3;
l1++;//printf("%d %d %d ",y1,x1,l1);
dfs();
}
else if(check(y1,x1-1)==1)
{ y1=y1;x1=x1-1;
num1=0;
l1++;
dfs();
}
else if(check(y1-1,x1)==1)
{ y1=y1-1;x1=x1;
num1=1;
l1++;//printf("%d %d %d ",y1,x1,l1);
dfs();
}
}
}
void dfs2()
{ if(y3==y2&&x3==x2) return ;
if(num2==0)
{
if(check(y3+1,x3)==1)
{ y3=y3+1;x3=x3;
num2=3;
l2++;
dfs2();
}
else if(check(y3,x3+1)==1)
{ y3=y3;x3=x3+1;
num2=0;
l2++;
dfs2();
}
else if(check(y3-1,x3)==1)
{ y3=y3-1;x3=x3;
num2=1;
l2++;
dfs2();
}
else if(check(y3,x3-1)==1)
{ y3=y3;x3=x3-1;
num2=2;
l2++;
dfs2();
}
}
else if(num2==1)
{
if(check(y3,x3+1)==1)
{ y3=y3;x3=x3+1;
num2=0;
l2++;
dfs2();
}
else if(check(y3-1,x3)==1)
{ y3=y3-1;x3=x3;
num2=1;
l2++;
dfs2();
}
else if(check(y3,x3-1)==1)
{ y3=y3;x3=x3-1;
num2=2;
l2++;
dfs2();
}
else if(check(y3+1,x3)==1)
{ y3=y3+1;x3=x3;
num2=3;
l2++;
dfs2();
}
}
else if(num2==2)
{
if(check(y3-1,x3)==1)
{ y3=y3-1;x3=x3;
num2=1;
l2++;
dfs2();
}
else if(check(y3,x3-1)==1)
{ y3=y3;x3=x3-1;
num2=2;
l2++;
dfs2();
}
else if(check(y3+1,x3)==1)
{ y3=y3+1;x3=x3;
num2=3;
l2++;
dfs2();
}
else if(check(y3,x3+1)==1)
{ y3=y3;x3=x3+1;
num2=0;
l2++;
dfs2();
}
}
else if(num2==3)
{
if(check(y3,x3-1)==1)
{ y3=y3;x3=x3-1;
num2=2;
l2++;
dfs2();
}
else if(check(y3+1,x3)==1)
{ y3=y3+1;x3=x3;
num2=3;
l2++;
dfs2();
}
else if(check(y3,x3+1)==1)
{ y3=y3;x3=x3+1;
num2=0;
l2++;
dfs2();
}
else if(check(y3-1,x3)==1)
{ y3=y3-1;x3=x3;
num2=1;
l2++;
dfs2();
}
}
}
void bfs()
{
head=0;
tail=1;
map[y][x]=1;
sq[1].x=y;
sq[1].y=x;
sq[1].pre=0;
while(head!=tail)
{
head++;
for( k=0;k<4;k++)
{p=sq[head].x+fx[k];
q=sq[head].y+fy[k];
if(check(p,q)==1)
{
tail=tail+1;
sq[tail].x=p;
sq[tail].y=q;
sq[tail].pre=head;
map[p][q]=1;
if(sq[tail].x==y2&&sq[tail].y==x2)
{
while(sq[tail].pre!=0)
{
tail=sq[tail].pre;
l3++;
}
return ;
}
}
}
}
}
int main()
{
int k1,k2,k3,t,w,h,i,j;
char Map[100][100];
scanf("%d",&t);
while(t--)
{ memset(map,-1,sizeof(map));
memset(Map,0,sizeof(Map));
memset(sq,0,sizeof(sq));
scanf("%d %d",&w,&h);
for(i=1;i<=h;i++)
{ getchar();
for(j=1;j<=w;j++)
{scanf("%c",&Map[i][j]);
if(Map[i][j]=='#') map[i][j]=1;
else if(Map[i][j]=='.') map[i][j]=0;
else if(Map[i][j]=='S') {map[i][j]=0;y=i;x=j;}
else if(Map[i][j]=='E') {map[i][j]=0;y2=i;x2=j;}
}
}
y1=y;x1=x;l1=1;num1=0;
dfs();
y3=y;x3=x;l2=1;num2=0;
dfs2();
l3=1;
bfs();
printf("%d %d %d\n",l1,l2,l3);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator