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

贴个垃圾代码

Posted by 422245257 at 2019-09-05 15:57:34 on Problem 2632
#include<cstdio>
#include<cstring>
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b) 
using namespace std;
int a,b,n,m,t;
int di[105][105][2];
bool mark[105][105];
char s[10];
struct node{
	int x;int y;
}T[105];
int main(){
	int i,j,k,l;
	int flag=0,num1,num2;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d %d %d",&a,&b,&n,&m);
		flag=0;
		memset(mark,false,sizeof(mark));
		for(i=1;i<=n;i++){
			scanf("%d %d %s",&j,&k,s);
			mark[j][k]=true;
	        switch(s[0]){
	        	case 'N':di[j][k][0]=0;break;
	        	case 'S':di[j][k][0]=2;break;
	        	case 'E':di[j][k][0]=3;break;
	        	case 'W':di[j][k][0]=1;break;
			}
			di[j][k][1]=i;
			T[i].x=j;T[i].y=k;
		}
		for(i=1;i<=m;i++){
			scanf("%d %s %d",&j,s,&k);
			if(flag!=0) continue;
			num1=j;
			switch(s[0]){
				case 'F':
					switch(di[T[j].x][T[j].y][0]){
						case 0:if(T[j].y+k>b){
							flag=1;
						}
						l=T[j].y+1;
						while(l<=(min(b,T[j].y+k))&&!mark[T[j].x][l])
						l++;
						if(l<=(min(b,T[j].y+k))){
							flag=2;num2=di[T[j].x][l][1];
							break;
						}
						else if(flag==1) break;
						mark[T[j].x][T[j].y]=false;
						di[T[j].x][T[j].y+k][0]=di[T[j].x][T[j].y][0];
						T[j].y+=k;
							mark[T[j].x][T[j].y]=true;
							di[T[j].x][T[j].y][1]=j;
						break;
						case 1:if(T[j].x-k<=0){
							flag=1;
						}
						l=T[j].x-1;
						while(l>=(max(1,T[j].x-k))&&!mark[l][T[j].y])
						l--;
						if(l>=(max(1,T[j].x-k))){
							flag=2;num2=di[l][T[j].y][1];
							break;
						}
						else if(flag==1) break;
						mark[T[j].x][T[j].y]=false;
						di[T[j].x-k][T[j].y][0]=di[T[j].x][T[j].y][0];
						T[j].x-=k;
							mark[T[j].x][T[j].y]=true;
							di[T[j].x][T[j].y][1]=j;
						break;
						case 2:if(T[j].y-k<=0){
							flag=1;
						}
						l=T[j].y-1;
						while(l>=(max(1,T[j].y-k))&&!mark[T[j].x][l])
						l--;
						if(l>=(max(1,T[j].y-k))){
							flag=2;num2=di[T[j].x][l][1];
							break;
						}
						else if(flag==1) break;
						mark[T[j].x][T[j].y]=false;
						di[T[j].x][T[j].y-k][0]=di[T[j].x][T[j].y][0];
						T[j].y-=k;
							mark[T[j].x][T[j].y]=true;
							di[T[j].x][T[j].y][1]=j;
						break;
						case 3:if(T[j].x+k>a){
							flag=1;
						}
						l=T[j].x+1;
						while(l<=(min(a,T[j].x+k))&&!mark[l][T[j].y])
						l++;
						if(l<=(min(a,T[j].x+k))){
							flag=2;num2=di[l][T[j].y][1];
							break;
						}
						else if(flag==1) break;
						mark[T[j].x][T[j].y]=false;
						di[T[j].x+k][T[j].y][0]=di[T[j].x][T[j].y][0];
						T[j].x+=k;
							mark[T[j].x][T[j].y]=true;
							di[T[j].x][T[j].y][1]=j;
						break;
					}
					break;
				case 'L':k=k%4;for(l=1;l<=k;l++) di[T[j].x][T[j].y][0]=(di[T[j].x][T[j].y][0]+1)%4;break;
				case 'R':k=k%4;for(l=1;l<=k;l++) di[T[j].x][T[j].y][0]=(di[T[j].x][T[j].y][0]+3)%4;break;
			}
		}
		if(!flag) printf("OK\n");
		else if(flag==1)
		printf("Robot %d crashes into the wall\n",num1);
		else
		printf("Robot %d crashes into robot %d\n",num1,num2); 
	}
	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