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

过了N组数据,还是WA,不知道什么问题,麻烦大牛们帮忙检查一下........

Posted by always at 2009-04-29 23:31:10 on Problem 2632

#include<iostream>
using namespace std;


struct rob{
	int x;
	int y;
	char direction;
} robot[110];


struct operating{
	int number;
	char operation;
	int repeat;
} oper[110];


int main(){
	int case_num, length, width, rob_num, ins_num;
	int i, j, m, n, counter;
	int number[110];
	bool flag1, flag2, flag3;
	cin>>case_num;
	for(i=0; i<case_num; i++){
		cin>>length>>width;
		int **matrix = new int *[length];
		for(j=0; j<length; j++){
			matrix[j] = new int[width];
		}
		counter=0;
		memset(matrix, 0, sizeof(matrix));
		memset(number, 0, sizeof(number));
		cin>>rob_num>>ins_num;
		for(j=1; j<=rob_num; j++){
			cin>>robot[j].x>>robot[j].y>>robot[j].direction;
		}
		for(j=1; j<=ins_num; j++){
			cin>>oper[j].number>>oper[j].operation>>oper[j].repeat;
		}
		flag2 = true;
		flag3 = true;
		for(j=1; j<=ins_num; j++){
			flag1 = false;

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;								// 成功执行instruction
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;								// 成功执行instruction
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;								// 成功执行instruction
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;								// 成功执行instruction
				continue;
			}



			if(oper[j].operation=='L' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}



			if(oper[j].operation=='L' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}



			if(oper[j].operation=='L' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='L' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}





			if(oper[j].operation=='R' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==0)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}



			if(oper[j].operation=='R' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==1)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}



			if(oper[j].operation=='R' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==2)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}



			if(oper[j].operation=='R' && robot[oper[j].number].direction=='E' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'N';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='S' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'E';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='W' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'S';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}

			if(oper[j].operation=='R' && robot[oper[j].number].direction=='N' && (oper[j].repeat%4==3)){
				robot[oper[j].number].direction = 'W';
				flag1 = true;
			}
			if(flag1==true){
				counter++;
				continue;
			}


			if(oper[j].operation=='F' && robot[oper[j].number].direction=='E'){
				for(m=1; m<=oper[j].repeat; m++){
					robot[oper[j].number].x++;																				// 移动
					if(robot[oper[j].number].x > length){																// 撞墙
						cout<<"Robot "<<oper[j].number<<" crashes into the wall"<<endl;
						flag2 = false;
						break;
					}
					n=0;
					for(n=1; n<=rob_num; n++){
						if(robot[oper[j].number].x==robot[n].x && robot[oper[j].number].y==robot[n].y){			// crash
							if(oper[j].number==n)
								continue;
							cout<<"Robot "<<oper[j].number<<" crashes into robot "<<n<<endl;
							flag2 = false;
							break;
						}
					}
					if(flag2==false){
						flag3 = false;
						break;
					}
				}
				if(flag2==true)					// 不撞墙 && 不crash																									
					counter++;
			}
			if(flag3==false)
				break;


			if(oper[j].operation=='F' && robot[oper[j].number].direction=='S'){
				for(m=1; m<=oper[j].repeat; m++){
					robot[oper[j].number].y--;																				// 移动
					if(robot[oper[j].number].x < 1){																		// 撞墙
						cout<<"Robot "<<oper[j].number<<" crashes into the wall"<<endl;
						flag2 = false;
						break;
					}
					n=0;
					for(n=1; n<=rob_num; n++){
						if(robot[oper[j].number].x==robot[n].x && robot[oper[j].number].y==robot[n].y){			// crash
							if(oper[j].number==n)
								continue;
							cout<<"Robot "<<oper[j].number<<" crashes into robot "<<n<<endl;
							flag2 = false;
							break;
						}
					}
					if(flag2==false)
						break;
				}
				if(flag2==true)					// 不撞墙 && 不crash																									
					counter++;
			}
			if(flag3==false)
				break;
			


			if(oper[j].operation=='F' && robot[oper[j].number].direction=='W'){
				for(m=1; m<=oper[j].repeat; m++){
					robot[oper[j].number].x--;																				// 移动
					if(robot[oper[j].number].x < 1){																		// 撞墙
						cout<<"Robot "<<oper[j].number<<" crashes into the wall"<<endl;
						flag2 = false;
						break;
					}
					n=0;
					for(n=1; n<=rob_num; n++){
						if(robot[oper[j].number].x==robot[n].x && robot[oper[j].number].y==robot[n].y){			// crash
							if(oper[j].number==n)
								continue;
							cout<<"Robot "<<oper[j].number<<" crashes into robot "<<n<<endl;
							flag2 = false;
							break;
						}
					}
					if(flag2==false){
						flag3 = false;
						break;
					}
				}
				if(flag2==true)					// 不撞墙 && 不crash																									
					counter++;
			}
			if(flag3==false)
				break;


			if(oper[j].operation=='F' && robot[oper[j].number].direction=='N'){
				n=0;
				for(m=1; m<=oper[j].repeat; m++){
					robot[oper[j].number].y++;																				// 移动
					if(robot[oper[j].number].y > width){																// 撞墙
						cout<<"Robot "<<oper[j].number<<" crashes into the wall"<<endl;
						flag2 = false;
						break;
					}
					n=0;
					for(n=1; n<=rob_num; n++){
						if(robot[oper[j].number].x==robot[n].x && robot[oper[j].number].y==robot[n].y){			// crash
							if(oper[j].number==n)
								continue;
							cout<<"Robot "<<oper[j].number<<" crashes into robot "<<n<<endl;
							flag2 = false;
							break;
						}
					}
					if(flag2==false)
						break;
				}
				if(flag2==true)					// 不撞墙 && 不crash																									
					counter++;
			}
			if(flag3==false)
				break;
			
			//for(k=0; k<=rob_num; k++){
			//	if(execute[k]==false){
			//		flag3 = false;
			//		break;
			//	}
			//}
			//if(flag3==true)
			//	cout<<"OK"<<endl;
		}
		if(counter==ins_num)
			cout<<"OK"<<endl;
	}


	//for(j=0; j<length; j++){
	//	delete [length]matrix[j];
	//	matrix[j] = NULL;
	//}
	//delete [width]matrix;
	//matrix = NULL;


	system("pause");
	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