118 - Mutant Flatworld Explorers

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

Moderator: Board moderators

JayP
New poster
Posts: 1
Joined: Thu Apr 04, 2002 2:00 am

Post by JayP »

My program is being rejected by the judge, but I have not been able to find any test cases which cause it to give the wrong output. Can anyone think of some good input to test my program with?

Thanks :smile:
paulhryu
New poster
Posts: 45
Joined: Sat Jan 26, 2002 2:00 am
Contact:

Post by paulhryu »

Well, this is a straightforward problem, I don't think there's too much room for error, but did you do the scent thing so that after one robot is lost, no other robot will ever go off at that point?

Just helping... post your code and maybe I can help. It shouldn't be too long or something's wrong. (Haha I rhymed)
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

Don't forget that the scent is cumulative. Never reset it. The scent is also on the last location of the robot (the last valid grid point), not the hole itself.
Deimos
New poster
Posts: 3
Joined: Mon Apr 29, 2002 2:56 pm

Output limit exceeded

Post by Deimos »

here is my main function code:

well I know this one is a straight foward problem, but i just started on this site...

I think my problem is the EOF i dunno how to implement it. i tried several things but if I only get either worng answer cuz it will not enter the while, or Output limit exceeded when it does not get out (still don't get why i get that Output limit exceeded).

[c]while(scanf("%d %d %c\n%s",&x,&y,&o,&orders)==4)
{
lost=0;
for (i=0;i<strlen(orders);i++)
{
if (lost) break;else
switch(orders)
{
stuff to move and turn and mark where the robot fall of the grid.
}
}
printf("%d %d %c",x,y,o);if (lost) printf(" LOST\n"); else printf("\n");
}[/c]

Btw i also have probs to understand what happens on the corners, i mean if a robot goes off the grid on a corner should it be allowed to fall of in the other direcction it did not fall ? lets see, on the upper left corner a robot can fall heading North or East.

regards
D
Deimos
New poster
Posts: 3
Joined: Mon Apr 29, 2002 2:56 pm

sorry i thought i was posting on the problem 118 thread...

Post by Deimos »

this is problem 118
fpnc
System administrator
Posts: 201
Joined: Sun Oct 07, 2001 2:00 am
Location: Valladolid, Spain

Re: Output limit exceeded

Post by fpnc »

Deimos wrote:I think my problem is the EOF i dunno how to implement it.

i tried several things but if I only get either worng answer cuz it will not enter the while, or Output limit exceeded when it does not get out (still don't get why i get that Output limit exceeded).
In the 99% of the cases, Output Limit is done because your program enters an infinite loop, and usually it writes the same output once and another and another... In this case, I think it is related to your non-knowledge of managing EOF.

I can't recommend you to read the input in this way:

[c]while(scanf("%d %d %c\n%s",&x,&y,&o,&orders)==4)[/c]

Personally, I prefer this:

[c]while (!feof(stdin)) {
scanf(" %d %d %c ", &x, &y, &o);
scanf(" %s ", &orders);
/* ... process this entry ... */
}[/c]

You can assume that after every 2 numbers and a character you'll find a string, because the input file is valid (this is that you won't find any entry which does not adjust to the statement), so try to find out the EOF before reading a test case, and if we have not EOF, then read a test case and process it.

Also, please note the blank spaces before %d, after %c and before and after %s; with these, you'll skip blank spaces and "\n" so you won't have to bother about them anymore.

Hope this helps. Best regards,
Best regards,

Fernando N
Deimos
New poster
Posts: 3
Joined: Mon Apr 29, 2002 2:56 pm

thanks for your help

Post by Deimos »

i finally got the correct answer, but i think the problem was my definitions of the arrays where i stored orders data and the scent.

Any how your way to get data seems more efficient and bug free :)
thanks
Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann »

Fernando, can you explain why you can't recommend his input code? This is the way I always did it (well, without the '\n').
judge
System administrator
Posts: 8
Joined: Sun Oct 07, 2001 2:00 am
Contact:

Post by judge »

Stefan Pochmann wrote:Fernando, can you explain why you can't recommend his input code? This is the way I always did it (well, without the '\n').
Well, maybe I shouldn't have said that :-?

First, I'm a Pascal programmer, not a C programmer, so I tend to do the things in the Pascal way. Related to that, I find the code I propose easier to trace in case of problems.

Second, I do NOT like seeing things like "\n" or even "\^[\n]" in a scanf sentence. Scanf is something "obscure" for me, so I prefer to use it in a simply way. I know that these kind of things should work, but I don't rely on them...

Third, in the last contest, one of my friends (and competitors :) ) had an Output Limit answer just because of the EOF matter, and it was solved by checking for EOF using feof.

I know that the EOF, and more generally, the way the input file is written, is a common source of problems. Because of that, I prefer to do things easier. 1 feof + 2 scanf is easier (to me) than 1 scanf with \n inside it.

But, I'm pretty sure that a C guru can demonstrate me the goodness of the scanf function, so I won't argue with anyone about this matter :)

P.S.: Pascal forever!!! :P
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

I always do [cpp]while(scanf("%d%d",&A,&B)!=EOF)[/cpp].
Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann »

Nah, in C++ it should look like this:
[cpp]
while( cin >> a >> b ){ ... }
[/cpp]
Only situation where I don't do this is if input speed is crucial. C++ input sucks big time. I think my "Babelfish" solution from the last was too slow mostly because of that.
C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 »

scanf is the paradigm of all input routines. I wish someone would take the time and implement format strings for streams:)
cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra »

Hi!

Don't forget that you only have to delete this order when your robot get out of grid...

Don't delete next orders (if they are Ok for example turning because it have the influence on the answer)...

I hope It will help :)
Betovsky
New poster
Posts: 26
Joined: Wed Jun 05, 2002 7:30 pm
Location: Portugal

Post by Betovsky »

same prob here...
i have the scente working, ingoring commando too

using the sample input (has the LOSt thing and ignoring command)
on the prob it works great but on the judge ives wrong anser :(
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

118 Help!!!

Post by Subeen »

I don't understand why my prog. got W.A. :(
Can someone help me with some inputs & outputs of this program?
Post Reply

Return to “Volume 1 (100-199)”