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

phonix
New poster
Posts: 1
Joined: Thu Aug 17, 2006 2:31 pm
Location: Iran/Mashhad
Contact:

118 : I am getting mad

Post by phonix » Wed Aug 23, 2006 6:26 pm

I tested my program with all samples on the board and it work correctly. but i still getting WA. can somebody help me and tell me why????

this is my code:

Code: Select all

#include <iostream.h>
#include <string.h>

int n,m,x,y,d[3];
char movelist[200];
bool scent[51][51];

char direction()
{
	if  (d[1]== 1)
		return 'N';
	else if (d[1]==-1)
		return 'S';
	else if (d[0]== 1)
		return 'E';
	else 
		return 'W';
}
bool move(char mo)
{
	int temp;
	bool sw=true;
	if (mo=='F')
	{
		x+=d[0];
		y+=d[1];
		if (x>n||x<0||y<0||y>m)
		{
			x-=d[0];
			y-=d[1];
			if (scent[x][y])
			{
				scent[x][y]=false;
				sw=false;
			}
		}
	}
	else if (mo=='R')
	{
		temp=d[0];
		d[0]=d[1];
		d[1]=-temp;
	}
	else if (mo=='L')
	{
		temp=d[1];
		d[1]=d[0];
		d[0]=-temp;
	}
	return sw;
}
void main()
{
	int i,j;
	char dir;
	bool sw;
	for (i=0;i<51;i++)
		for (j=0;j<51;j++)
			scent[i][j]=true;
	cin >>n>>m;
	while (cin>>x>>y>>dir)

	{
		if (dir=='N')		{d[0]= 0;d[1]= 1;}
		else if(dir=='E')	{d[0]= 1;d[1]= 0;}
		else if(dir=='S')	{d[0]= 0;d[1]=-1;}
		else if(dir=='W')	{d[0]=-1;d[1]= 0;}
		cin.getline(movelist,100,'\n');
		cin.getline(movelist,100,'\n');
		sw=true;
		for (i=0;i<strlen(movelist)&&sw;i++)
			sw=move(movelist[i]);
		if (sw)
			cout<<x<<" "<<y<<" "<<direction()<<endl;
		else
			cout<<x<<" "<<y<<" "<<direction()<<" LOST\n";
	}
}
i think it's because of my nationality. iran is sanctioned by america so iranian code r not working correct :lol:

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Output limit exited!~

Post by smilitude » Thu Nov 16, 2006 2:09 pm

:S i am getting output limit exited.. how could that happen to this simple code

Code: Select all

    
    
    DILAM KUAITTTTTTTTTTAAAAAAA!
    
    
Last edited by smilitude on Fri Nov 17, 2006 11:12 am, edited 1 time in total.
fahim
#include <smile.h>

User avatar
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

:(

Post by smilitude » Fri Nov 17, 2006 11:12 am

i got output limit exited cause i wrote

Code: Select all

while(scanf("%d %d %c",&current.x,&current.y,&ch)) { 
instead of

Code: Select all

while(scanf("%d %d %c",&current.x,&current.y,&ch)==3) { 
thats all...
fahim
#include <smile.h>

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue » Sat Dec 02, 2006 11:46 am

I've tried the input above and compared to the lantimilan's output.
It's absolutely identical, so I'm very confused why my code is wrong.
Does someone can help?

Code: Select all

/* removed after AC */
Last edited by razor_blue on Mon Dec 04, 2006 3:47 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sun Dec 03, 2006 2:46 am

I think you havent understood the 'scent' properly. The problem states
lost robots leave a robot ``scent'' that prohibits future robots from dropping off the world at the same grid point
Check the samples...

Input:

Code: Select all

3 3
0 0 S
FFFFFF
0 0 W
FFFFFF
Output:

Code: Select all

0 0 S LOST
0 0 W
Because the first robot is dropped off from (0,0) and thus leaves a 'scent', the second robot sees the 'scent' in (0,0) and so it remains in the grid. Hope it helps.
Ami ekhono shopno dekhi...
HomePage

razor_blue
New poster
Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Post by razor_blue » Mon Dec 04, 2006 3:46 am

Thank you Jan, now I understand the problem and I got AC.

joebin
New poster
Posts: 12
Joined: Fri Dec 29, 2006 7:18 am
Location: Taiwan
Contact:

Post by joebin » Mon Apr 16, 2007 7:09 am

i tried above all , but i got WA , either.
following is my code :

Code: Select all

#include<iostream>
using namespace std;
int main( int argc, char * argv[] )
{
  int a,i,j,m,n,l[51][51],x,y,p[4]={1,1,-1,-1};
  char k,d[4]={'N','E','S','W'},t[100];
  cin >>m>>n;
  for(i=0;i<=m;i++)
    for(j=0;j<=n;j++)
      l[i][j]=1;
  while(cin >>x>>y>>k!=NULL){
    j=0;i=0;a=1;
    while(d[j]!=k)
      j++;
    cin.getline(t,100);cin.getline(t,100);
    while(t[i]!='\0'){
      if(t[i]=='F'){
        if(j%2==0)
          y+=p[j];
        else
          x+=p[j];
      }
      if(t[i]=='R')
        j=(j+1)%4;
      if(t[i]=='L')
        j=(j+3)%4;
      i++;
      if(x>m||y>n||x<0||y<0){
        if((j%2==0&&l[x][y-p[j]]==0)||(j%2==1&&l[x-p[j]][y]==0)){
          if(j%2==0)
            y-=p[j];
          else
            x-=p[j];
        }
        else{
          a=0;
          if(j%2==0)
            y-=p[j];
          else
            x-=p[j];
          l[x][y]=0;
          cout <<x<<" "<<y<<" "<<d[j]<<" LOST"<<endl;
          break;
        }
      }
    }
    if(a==1)
      cout <<x<<" "<<y<<" "<<d[j]<<endl;
  }
  return 0;
}
could anyone tell me why ?? THX!!

gareve25
New poster
Posts: 5
Joined: Mon Feb 11, 2008 8:38 pm

WA...help

Post by gareve25 » Tue Mar 04, 2008 2:35 am

my code works with that big input, but im still getting WA, can someone tell me why...

Code: Select all

Accepeted...
I try and try this problem, for a long time, and my two errors are this:
-If the robor fall in a corner the signal have effect on 1 or 2 or 3 or 4 squares
- a newline at the end of output(!!!!!!!!!! mi long time error, frustating);
Last edited by gareve25 on Thu Aug 07, 2008 2:02 pm, edited 1 time in total.
Just beginning to make my brain more strong

amr saqr
New poster
Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

Re: 118 WA: wtf

Post by amr saqr » Wed Jul 30, 2008 9:05 pm

There is a mistake in the problem description

All instruction strings will be less than 100 characters in length.

when i submitted my code with a 100 char array it gave me WA, and when i changed it to 101 with the same logic it was AC

be careful ...
C++ Is The Best.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 118 WA: wtf

Post by Obaida » Thu Jul 31, 2008 11:05 am

There is no fault in the program description.
For a 100 length string you can't get Accepted by a 100 SIZE array.(Think why :wink: ).
You will get the answer.
try_try_try_try_&&&_try@try.com
This may be the address of success.

amr saqr
New poster
Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

Re: 118 WA: wtf

Post by amr saqr » Thu Jul 31, 2008 11:26 am

Again :D,

All instruction strings will be less than 100 characters in length.

less less less less less :D

that means that there will be 99 instructions at maximum not 100, so it's enough to make an array of 100 characters, 99 for the instructions and an extra char for the null character, but the 100 array didn't work, when i changed it to 101 i got AC, that's why i said there is a mistake in the problem description :).
C++ Is The Best.

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Re: 118 WA: wtf

Post by sakhassan » Mon Nov 03, 2008 7:48 am

Getting WA :( .. is my logic wrong :( ... Please help me. This is ma code:

Code: Select all


#include<stdio.h>

#define N 102

int cur_x,cur_y;
int scent[N][N];

void forward(char d)
{

    if(d=='W')
        cur_x -=1;
    else if(d=='E')
        cur_x += 1;
    else if(d=='N')
        cur_y += 1;
    else
        cur_y -= 1;


}

char move_dir(char d,char m)
{
        if(m=='L')
        {
                if(d=='W')
                    return 'S';
                else if(d=='S')
                    return 'E';
                else if(d=='E')
                    return 'N';
                else if(d=='N')
                    return 'W';
        }
        else
        {
                if(d=='W')
                    return 'N';
                else if(d=='N')
                    return 'E';
                else if(d=='E')
                    return 'S';
                else if(d=='S')
                    return 'W';
        }
}


int main()
{


        int n,m;
        int x,y;
        char d;
        char str[N],dir[N];
        char ch;
        int flag;
        int temp_x,temp_y;
        char cur_d;
        int i;

        scanf("%d%d",&n,&m);
        gets(str);



        while(gets(str))
        {

                sscanf(str,"%d %d %c",&x,&y,&d);
                gets(dir);
                cur_x = x;
                cur_y = y;
                cur_d = d;

                flag = 1;
                for(i=0;dir[i];i++)
                {

                        ch = dir[i];
                        if(ch=='F')
                        {
                            temp_x = cur_x;
                            temp_y = cur_y;
                            forward(cur_d);
                            if(scent[cur_x][cur_y] || (cur_x<0 || cur_y<0) )
                            {
                                cur_x = temp_x;
                                cur_y = temp_y;
                            }

                        }
                        else
                            cur_d = move_dir(cur_d,ch);

                        if( cur_x >= (n-1) || cur_y>= (m-1))
                        {
                                flag = 0;
                                scent[cur_x][cur_y] = 1;
                                break;
                        }

                }

                printf("%d %d %c",cur_x,cur_y,cur_d);
                if(!flag)
                    printf(" LOST");
                printf("\n");


        }

        return 0;
}




Time that gone is gone forever ...

porker2008
New poster
Posts: 21
Joined: Wed Oct 08, 2008 7:04 am

To "sakhassan".

Post by porker2008 » Tue Nov 04, 2008 12:51 pm

Your solution even can not handle the example input!!!

Sample input:

Code: Select all

5 3
1 1 E
RFRFRFRF
3 2 N
FRRFLLFFRRFLL
0 3 W
LLFFFLFLFL
Sample output:

Code: Select all

1 1 E
3 3 N LOST
2 3 S
Your code produces:

Code: Select all

1 1 E
3 3 N LOST
0 3 S LOST
Please check your program. If the preview robots leave a "scent" on a block, the latter robots cannot leave the board from that block any more.

When the robots meet a block that have a scent on it and the next action will make the robots lost, you should ignore the action and check the next action until all the action are acted or ignored.

BTW, you can use integers to recognize the dirctions instead of using characters.
For instance, you can use 0 for N, 1 for E, 2 for S and 3 for W.
When you meet a "L", you can change the dirction from i to (i+3)%4.
When you meet a "R", you can change the dirction from i to (i+1)%4.
That can make you handle the direction more easily.

peratu
New poster
Posts: 7
Joined: Sat Jul 10, 2010 9:22 am

118 - RE

Post by peratu » Wed Jul 14, 2010 5:55 pm

Hi.

I have made this problem using java language, and the judge always give me a Runtime Error.
I have tested my program with a lot of input tests cases, and the results are correct, because I check them on UVA toolkit.

I don't know where the problem is. Here is my code:

#### EDITED ####

I have got AC changing the name of the main class to Main , and changing some functions like this:

public static void processInstruction()

to:

static void processInstruction()

(just remove "public" keyword)
###############

matt123437
New poster
Posts: 1
Joined: Sun Oct 03, 2010 3:42 am

Java runtime error problem 118

Post by matt123437 » Sun Oct 03, 2010 3:54 am

I'm new to coding in java on the UVA judge. I seem to be getting the correct output from my code but I'm getting a runtime error when I submit to the judge. I'm also not sure if I'm checking for EOF in the correct manner(scan.hasNextLine()). Here is my code

Code: Select all

import java.util.*;
/**
 *
 * 
 */
   public class Main {

    /**
     * @param args the command line arguments
     */
     public static void main(String[] args) {
        int x_max = 0;
        int y_max = 0;
        int x =0;
        int y =0;
        boolean no_lost = true;
        boolean[][]scent;
        String orien = "";
        String moves = "";
        Scanner scan = new Scanner(System.in);
        //get max vals
        x_max = scan.nextInt();
        y_max = scan.nextInt();
        scent = new boolean[x_max+2][y_max+2];
        while(scan.hasNextInt()){
            x = scan.nextInt();
            y = scan.nextInt();
            orien = scan.next();
            scan.nextLine();
            moves = scan.nextLine();
            for(int i=0;i<moves.length();i++){
                   if(moves.substring(i, i+1).equals("R")){
                       if(orien.equals("N"))orien="E";
                       else if(orien.equals("S"))orien = "W";
                       else if(orien.equals("E"))orien = "S";
                       else if(orien.equals("W"))orien = "N";
                   }
                   if(moves.substring(i, i+1).equals("L")){
                      if(orien.equals("N"))orien="W";
                      else if(orien.equals("S"))orien="E";
                      else if(orien.equals("E"))orien="N";
                      else if(orien.equals("W"))orien="S";
                   }
                   if(moves.substring(i, i+1).equals("F")){
                      if(orien.equals("N"))y++;
                      else if(orien.equals("S"))y--;
                      else if(orien.equals("E"))x++;
                      else if(orien.equals("W"))x--;
                   }
                if((y > y_max || x > x_max)||(y<0||x<0)){
                   if(scent[x][y]==true){
                       if(y>y_max)y--;
                       if(x>x_max)x--;
                   }
                   else{
                       if(y >y_max){
                           scent[x][y]=true;
                           y=y_max;
                       }
                       if(x >x_max){
                           scent[x][y]=true;
                           x=x_max;
                       }
                       System.out.println(x+" "+y+" "+orien+" LOST");
                       no_lost = false;
                       i = moves.length();
                   }
                }
            
            }
            if(no_lost) System.out.println(x+" "+y+" "+orien);
            no_lost = true;
        }
    }
}

Thanks

Post Reply

Return to “Volume 1 (100-199)”