10500 - Robot maps

All about problems in Volume 105. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

10500 WA !!!! HELP

Post by Chok »

Hi all,
I'm getting lots of WA for this easy problem. Plz help me to find out my error. Here is my code. Thanx in advance.

Code: Select all

#include<stdio.h>
#include<string.h>

#define mm(a,b) memset((a),(b),sizeof(a))

#define MAX 11

char grid[MAX][MAX];
char rob[MAX][MAX];

int N,M,cnt;

void visit(int i,int j)
{	
	int flag=0;
	while(1)
	{
		flag=0;
		if(i-1>=0 && grid[i-1][j]!='X' && rob[i-1][j]!='0')			//North
		{
			i--;	
			rob[i][j]=grid[i][j];
			++cnt;
			flag=1;			
		}
		if(flag)
			continue;
		if(j+1<M && grid[i][j+1]!='X' && rob[i][j+1]!='0')			//East
		{
			j++;
			rob[i][j]=grid[i][j];
			cnt++;				
			flag=1;			
		}
		if(flag)
			continue;
		if(i+1<N && grid[i+1][j]!='X' && rob[i+1][j]!='0')			//South
		{
			i++;
			rob[i][j]=grid[i][j];
			cnt++;
			flag=1;
		}
		if(flag)
			continue;
		if(j-1>=0 && grid[i][j-1]!='X' && rob[i][j-1]!='0')			//West
		{
			j--;	
			rob[i][j]=grid[i][j];
			cnt++;
			flag=1;
		}
		if(flag==0)
			return;
	}	
}


int main()
{
	int i,j,sc,sr,flag=0;
	char temp;
	//freopen("10500.in","r",stdin);
	//freopen("10500.out","w",stdout);
	while(scanf("%d %d",&N,&M),N!=0 && M!=0)
	{
		scanf("%d %d\n",&sr,&sc);
		mm(grid,0);
		mm(rob,0);
		for(i=0;i<N;i++)
		{
			j=0;
			while(j!=M)
			{
				scanf("%c",&temp);
				if(temp!='X' && temp!='0')
					continue;
				grid[i][j]=temp;
				rob[i][j]='?';
				j++;
			}
		}
		cnt=0;
		rob[sr-1][sc-1]='0';
		visit(sr-1,sc-1);
		for(i=0;i<N;i++)
		{
			for(j=0;j<M;j++)
			{
				if(rob[i][j]=='0')
				{
					if(i-1>=0)
						rob[i-1][j]=grid[i-1][j];
					if(i+1<N)
						rob[i+1][j]=grid[i+1][j];
					if(j-1>=0)
						rob[i][j-1]=grid[i][j-1];
					if(j+1<M)
						rob[i][j+1]=grid[i][j+1];
				}
			}
		}
		if(flag)
			puts("");
		for(i=0;i<M;i++)
			printf("|---");
		printf("|\n");
		for(i=0;i<N;i++)
		{
			for(j=0;j<M;j++)
				printf("| %c ",rob[i][j]);
			puts("|");
			for(j=0;j<M;j++)
				printf("|---");
			printf("|\n");
		}
		printf("\nNUMBER OF MOVEMENTS: %d\n",cnt);
		flag=1;
	}
	return 0;
}

Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

No Reply

Post by Chok »

Hi all,
I've created the above thread 12 days ago. but no reply till now !!!!. I'm beginner and not good with recursion. Please help me.

Why No reply !!!!!

roticv
Learning poster
Posts: 63
Joined: Sat Dec 11, 2004 9:28 am

Post by roticv »

Your output definitely look wrong. You did not read the problem description properly.

Code: Select all


|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| X | 0 | X | 0 | X |
|---|---|---|---|---|
| X | 0 | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | X | X | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 7

|---|---|---|---|---|
| 0 | 0 | X | ? | ? |
|---|---|---|---|---|
| X | X | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 1

|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | X | 0 | X | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 99

|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 4

|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 4


WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

Yes, sorry. I didn't check the posted output properly. All characters should be centered as in roticv's output. Both outputs are identical ( I removed the additional empty lines) but it's still P.E.?!?!

Code: Select all

|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | 0 | 0 | X |
|---|---|---|---|---|
| X | 0 | X | 0 | X |
|---|---|---|---|---|
| X | 0 | 0 | 0 | X |
|---|---|---|---|---|
| ? | X | X | X | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 7

|---|---|---|---|---|
| 0 | 0 | X | ? | ? |
|---|---|---|---|---|
| X | X | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|
| ? | ? | ? | ? | ? |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 1

|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | X | 0 | X | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | X | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|
| ? | ? | ? | ? | ? | ? | ? | ? | ? | ? |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|---|

NUMBER OF MOVEMENTS: 99

|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 0

|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
|---|---|---|---|---|

NUMBER OF MOVEMENTS: 4

|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|
| 0 |
|---|

NUMBER OF MOVEMENTS: 4

farzane
New poster
Posts: 26
Joined: Thu Jun 15, 2006 9:26 am

10500 PE

Post by farzane »

could any one please tell me what's wrong in this code that I got
P.E:



#include<iostream.h>
#include<stdio.h>
//#include<fstream.h>

enum status{con,stop};

void main(){
status st;
char board[11][11],map[11][11],str[10],vis[11][11];
int i,k,j,m,n,steps;
int curX,curY;

//ifstream cin("10500.in");
cin>>n>>m;
while(n!=0 && m!=0){
cin>>curX>>curY;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin>>board[j];
map[j]='?';
vis[j]=0;
}
cin.getline(str,10);
}
map[curX][curY]='0';
vis[curX][curY]=1;
//perX=curX;
//perY=curY;
st=con;
steps=0;
while(st==con){
if(curX>1)map[curX-1][curY]=board[curX-1][curY];
if(curY>1)map[curX][curY-1]=board[curX][curY-1];
if(curX<n)map[curX+1][curY]=board[curX+1][curY];
if(curY<m)map[curX][curY+1]=board[curX][curY+1];

if((curX-1)>=1 && /*curX-1!=perX*/vis[curX-1][curY]!=1){
if(board[curX-1][curY]=='0'){
// perX=curX;
// perY=curY;

curX--;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX-1][curY]='X';
//}
}
if((curY+1)<=m && /*curY+1!=perY*/vis[curX][curY+1]!=1){
if(board[curX][curY+1]=='0'){
// perX=curX;
// perY=curY;
curY++;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX][curY+1]='X';
//}
}
if((curX+1)<=n && /*urX+1!=perX*/vis[curX+1][curY]!=1){
if(board[curX+1][curY]=='0'){
//perX=curX;
//perY=curY;
curX++;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX+1][curY]='X';
// }
}
if((curY-1)>=1 && /*curY-1!=perY*/vis[curX][curY-1]!=1){
if(board[curX][curY-1]=='0'){
//perX=curX;
//perY=curY;
curY--;
steps++;
map[curX][curY]='0';
vis[curX][curY]=1;
continue;
}//else{
// map[curX][curY-1]='X';
// }
}
st=stop;
}
//cout<<endl;
for(i=1;i<=m;i++)
cout<<"|---";
cout<<"|"<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
cout<<"| "<<map[j]<<" ";
cout<<"|"<<endl;
for(k=1;k<=m;k++)
cout<<"|---";
cout<<"|"<<endl;

}

cout<<endl;
cout<<"NUMBER OF MOVEMENTS: "<<steps<<endl<<endl;
cin>>n>>m;
}
}

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10500 PE

Post by Martin Macko »

farzane wrote:could any one please tell me what's wrong in this code that I got
P.E:
Read the problem statement carefully
problem statement wrote:The application outputs an empty line, followed by the robot map, an empty line, and a line containing a message of the movements needed to reach that map.
What are those two endl in your code for?
farzane's code wrote:cout<<"NUMBER OF MOVEMENTS: "<<steps<<endl<<endl;

farzane
New poster
Posts: 26
Joined: Thu Jun 15, 2006 9:26 am

Post by farzane »

I think this two endl are needed.But I also tried your suggestion,still got PE
Please help.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Martin is right, you don't need both. You get an extra blank line at the end of the output and you are missing the leading blank line. Please remove the code after you get AC.

Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

10500

Post by Chok »

Hello All,
I've got several WA for the problem 10500. Someone plz help me to find out my error. What i'm missing ?? My code passed all the input given in the other threads. Plz help me. Here is my code. Thanks in advance.

Code: Select all


#include<stdio.h>
#include<string.h>

#define mm(a,b) memset((a),(b),sizeof(a))

#define MAX 100

char grid[MAX][MAX];
char rob[MAX][MAX];

int N,M,cnt;

void visit(int i,int j)
{	
	int flag=0;
	while(1)
	{
		flag=0;
		if(i-1>=0 && grid[i-1][j]!='X' && rob[i-1][j]!='0')			//North
		{
			i--;	
			rob[i][j]=grid[i][j];
			++cnt;
			flag=1;			
		}
		if(flag)
			continue;
		if(j+1<M && grid[i][j+1]!='X' && rob[i][j+1]!='0')			//East
		{
			j++;
			rob[i][j]=grid[i][j];
			cnt++;				
			flag=1;			
		}
		if(flag)
			continue;
		if(i+1<N && grid[i+1][j]!='X' && rob[i+1][j]!='0')			//South
		{
			i++;
			rob[i][j]=grid[i][j];
			cnt++;
			flag=1;
		}
		if(flag)
			continue;
		if(j-1>=0 && grid[i][j-1]!='X' && rob[i][j-1]!='0')			//West
		{
			j--;	
			rob[i][j]=grid[i][j];
			cnt++;
			flag=1;
		}
		if(flag==0)
			break;
	}	
}


int main()
{
	int i,j,sc,sr,flag=0;
	char temp;
	//freopen("10500.in","r",stdin);
	//freopen("10500.out","w",stdout);
	while(scanf("%d %d",&N,&M),N!=0 && M!=0)
	{
		scanf("%d %d\n",&sr,&sc);
		mm(grid,0);
		mm(rob,0);
		for(i=0;i<N;i++)
		{
			j=0;
			while(j!=M)
			{
				scanf("%c",&temp);
				if(temp!='X' && temp!='0')
					continue;
				grid[i][j]=temp;
				rob[i][j]='?';
				j++;
			}
		}
		cnt=0;
		rob[sr-1][sc-1]='0';
		visit(sr-1,sc-1);
		for(i=0;i<N;i++)
		{
			for(j=0;j<M;j++)
			{
				if(rob[i][j]=='0')
				{
					if(i-1>=0)
						rob[i-1][j]=grid[i-1][j];
					if(i+1<N)
						rob[i+1][j]=grid[i+1][j];
					if(j-1>=0)
						rob[i][j-1]=grid[i][j-1];
					if(j+1<M)
						rob[i][j+1]=grid[i][j+1];
				}
			}
		}
		if(flag)
			puts("");
		for(i=0;i<M;i++)
			printf("|---");
		printf("|\n");
		for(i=0;i<N;i++)
		{
			for(j=0;j<M;j++)
				printf("| %c ",rob[i][j]);
			puts("|");
			for(j=0;j<M;j++)
				printf("|---");
			printf("|\n");
		}
		printf("\nNUMBER OF MOVEMENTS: %d\n",cnt);
		flag=1;
	}
	return 0;
}

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: Pr# 10500 Robot maps !!!! WA !!!!!! Help Plz

Post by Martin Macko »

There is already a thread on this problem. If there is a thread on a particular problem, please, use it to post your question and do not create a new one. (see http://online-judge.uva.es/board/viewto ... ight=10500, http://online-judge.uva.es/board/viewto ... ight=10500 and http://online-judge.uva.es/board/viewto ... ight=10500)
forum 'Volume CV' description wrote:All about problems in Volume CV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

Post by Chok »

Hi Martin Macko,
Forgot to search before posting !!!!! Sorry.... But where is my mistake in my code???? Thanks in advance.

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: Pr# 10500 Robot maps !!!! WA !!!!!! Help Plz

Post by Martin Macko »

Chok wrote:Hello All,
I've got several WA for the problem 10500. Someone plz help me to find out my error. What i'm missing ?? My code passed all the input given in the other threads. Plz help me. Here is my code. Thanks in advance.
Chok's main() wrote:......if(flag)
.........puts("");
You should write an empty line before every test case.
The problem statement wrote:The application outputs an empty line, followed by the robot map, an empty line, and a line containing a message of the movements needed to reach that map.

Chok
New poster
Posts: 48
Joined: Mon Jun 27, 2005 4:18 pm
Location: Hong Kong

Post by Chok »

Hi Martin Macko,
Thanks for your reply. But i've changed it, but still WA !!!!! :( :(

Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko »

Chok wrote:Hi Martin Macko,
Thanks for your reply. But i've changed it, but still WA !!!!! :( :(
Ok, I've just found your bug. Try this:

Code: Select all

5 3
3 2
X X X
X 0 X
X 0 X
X 0 X
X X X
0 0
The correct output is:

Code: Select all

|---|---|---|
| ? | X | ? |
|---|---|---|
| X | 0 | X |
|---|---|---|
| X | 0 | X |
|---|---|---|
| ? | 0 | ? |
|---|---|---|
| ? | ? | ? |
|---|---|---|

NUMBER OF MOVEMENTS: 1

deadhunter411
New poster
Posts: 8
Joined: Sat Mar 10, 2007 10:20 am

Post by deadhunter411 »

I've got several WA for the problem 10500.
Someone plz help me to find out my error.
thank you very much..

Code: Select all

remove after ac.

Post Reply

Return to “Volume 105 (10500-10599)”