Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位好心人看看我的代码,大家给的测试都过了,但还是WA,快哭了

Posted by youngdaxian at 2011-01-30 09:47:35 on Problem 2632
#include<stdio.h>
#include<string.h>
struct warehouse
{
	int  full;
	int  dir;
}a[102][102];
struct  numwhere
{
	int i,j;
}b[102];
int crashnum1,crashnum2,crashevent;
int  changedir(char dir)
{
   if(dir=='N')return  4;
   if(dir=='S')return  2;
   if(dir=='W')return  3;
   if(dir=='E')return  1;
   return 0;	
}
int judge(int num,int i,int j,int chang,int kuan)
{                       
	int k;
	if(i>chang||j>kuan||i<1||j<1){crashevent=1;return 0;}
	if(a[i][j].full==1){crashevent=2;for(k=1;k<=102;k++){if(k!=num&&b[k].i==i&&b[k].j==j){crashnum2=k;break;}}return 0;}
	a[i][j].full=1;
	return  1;
}
int main()
{
	int t,i,chang,kuan,num,m,n,j,k,flag,repeat;
	char dire;
	scanf("%d",&t);
	    for(i=0;i<t;i++)
		{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		flag=1;
		crashevent=0;
		crashnum1=0;
		crashnum2=0;
		scanf("%d%d",&chang,&kuan);
		scanf("%d%d",&n,&m);
		for(num=1;num<=n;num++){scanf("%d%d",&j,&k);a[j][k].full=1;b[num].i=j;b[num].j=k;scanf(" %c",&dire);a[j][k].dir=changedir(dire);printf("%d",a[j][k].dir);}
		for(j=0;j<m;j++){
			scanf("%d %c %d",&num,&dire,&repeat);
			if(flag==1)for(k=0;k<repeat;k++)
			{
			    if(dire=='L'){
    				if(--a[b[num].i][b[num].j].dir<1)a[b[num].i][b[num].j].dir=4;
    				continue;
    			}
				if(dire=='R')
				{
					if(++a[b[num].i][b[num].j].dir>4)a[b[num].i][b[num].j].dir=1;
					continue;
				}
				if(flag==0)continue;
				a[b[num].i][b[num].j].full=0;
				if(a[b[num].i][b[num].j].dir==1){if(judge(num,b[num].i+1,b[num].j,chang,kuan))a[++b[num].i][b[num].j].dir=1;else flag=0;crashnum1=num;}
				if(a[b[num].i][b[num].j].dir==2){if(judge(num,b[num].i,b[num].j-1,chang,kuan))a[b[num].i][--b[num].j].dir=2;else flag=0;crashnum1=num;}
				if(a[b[num].i][b[num].j].dir==3){if(judge(num,b[num].i-1,b[num].j,chang,kuan))a[--b[num].i][b[num].j].dir=3;else flag=0;crashnum1=num;}
				if(a[b[num].i][b[num].j].dir==4){if(judge(num,b[num].i,b[num].j+1,chang,kuan))a[b[num].i][++b[num].j].dir=4;else flag=0;crashnum1=num;}		
			}
		}
		if(flag)printf("OK\n");
		else {
			if(crashevent==1)printf("Robot %d crashes into the wall\n",crashnum1);
			if(crashevent==2)printf("Robot %d crashes into robot %d\n",crashnum1,crashnum2);
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator