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

shantanu18
New poster
Posts: 22
Joined: Tue Jul 20, 2010 9:55 pm

Re: 118 WA: wtf

Post by shantanu18 »

Please anyone can explain this 3rd case ?
2nd case:

Code: Select all

3 3 N LOST //so 3 3 coordinate is block
3rd Case:

Code: Select all

 LLFFFLFLFL
start 0 3 W
L -> 0 3 S  [change dir to left]
L -> 0 3 E 
F -> 1 3 E
F -> 2 3 E

[b]#F -> 3 3 E [this step is not valid becoz 3 3 already visited by 2nd robot] [so this step remain 2 3 E][/b]

L -> 2 3 N
F -> 2 4 N [this time it is lost becoz right boundary is x=5 y=3] 
SO result should be [b]2 3 N[/b]
How it is [b]2 3 S[/b]
zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: 118 WA: wtf

Post by zobayer »

@shantanu18, this is the correct move sequence for the 3rd case (considering the first 2)

Code: Select all

0 3 W
0 3 S
0 3 E
1 3 E
2 3 E
3 3 E
3 3 N
3 3 N
3 3 W
2 3 W
2 3 S
You mis-interpreted problem statement:
An instruction to move ``off'' the world from a grid point from which a robot has been previously lost is simply ignored by the current robot.
You can surely go with a cell with "scent" but you can not "fell off" the world from that cell.
Hope this helps.
You should not always say what you know, but you should always know what you say.
shantanu18
New poster
Posts: 22
Joined: Tue Jul 20, 2010 9:55 pm

Re: 118 WA: wtf

Post by shantanu18 »

Thanks zobayer for reply. I got the point. I got AC.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 118 WA: wtf

Post by brianfry713 »

Input:

Code: Select all

3 3
0 0 W
F
0 0 S
F
AC output:

Code: Select all

0 0 W LOST
0 0 S
Check input and AC output for thousands of problems on uDebug!
shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

WA(118 - Mutant Flatworld Explorers)

Post by shikhorroy »

I got WA....help me please.

Code: Select all

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>

#include <iostream>
#include<iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>

using namespace std;

#define MAX 10000007
#define PI acos(-1.0)
#define int64 long long
#define pb push_back
#define sf scanf
#define pf printf
#define READ(f) freopen(f, "r", stdin)
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))

int dx[]= {1,0,-1,0};
int dy[]= {0,1,0,-1}; //4 Direction: east, north, west, south
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
inline int get_index(char dir)
{
    if(dir == 'E') return 0;
    if(dir == 'N') return 1;
    if(dir == 'W') return 2;
    if(dir == 'S') return 3;
}
inline char get_dir(int index)
{
    if(index == 0) return 'E';
    if(index == 1) return 'N';
    if(index == 2) return 'W';
    if(index == 3) return 'S';
}
int main()
{
    READ("118 - Mutant Flatworld Explorers.in");
    int fx, fy;
    char dir;
    int rx, ry;
    string input;
    map<pair<int, int>, int>m;
    sf("%d %d",&fx, &fy);
    while(sf("%d %d %c\n",&rx, &ry, &dir) != EOF)
    {
        getline(cin,input);
        int l = input.length();
        int index = get_index(dir);
        bool flag = false;
        for(int i = 0; i < l; i++)
        {
            if(input[i] == 'R') index = (index + 3) % 4;
            else if(input[i] == 'L') index = (index + 5) % 4;
            else if(input[i] == 'F')
            {
                rx += dx[index];
                ry += dy[index];
                if(rx < 0 || rx > fx || ry < 0 || ry > fy)
                {
                    rx -= dx[index];
                    ry -= dy[index];
                    pair<int, int>pii;
                    pii = make_pair(rx, ry);
                    if(m.find(pii) == m.end()) m[pii] = 0;
                    else continue;
                    flag = true;
                    break;
                }
            }
        }
        dir = get_dir(index);
        pf("%d %d %c",rx, ry, dir);
        if(flag) pf(" LOST\n");
        else pf("\n");
    }
    return 0;
}
shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

Re: WA(118 - Mutant Flatworld Explorers)

Post by shikhorroy »

Yes, I found the problem and got AC.
sidsi
New poster
Posts: 7
Joined: Sun Mar 23, 2014 5:28 pm

Re: WA(118 - Mutant Flatworld Explorers)

Post by sidsi »

where is the problem??? :(

#include<stdio.h>
#include<string.h>
int main()
{
int x,y,c=0,m,n;char b[105],o;
char a[105][105][105];
memset(a,0,sizeof(a));
scanf("%d %d",&m,&n);
while(scanf("%d %d %c",&x,&y,&o)==3)
{getchar();c=0;
gets(b);
for(int i=0;i<strlen(b);i++)
{
if(o=='N')
{
if(b=='L')
o='W';
else if(b=='R')
o='E';
else if(b=='F'&&a[x+'0'][y+'0'][o+'0']!=1)
{
x=x;y=y+1;
if(x>=0&&x<=m&&y>=0&&y<=n)
continue;
else
{
x=x;y=y-1;c=1;
a[x+'0'][y+'0'][o+'0']=1;
break;
}
}
}
else if(o=='S')
{
if(b=='L')
o='E';
else if(b=='R')
o='W';
else if(b=='F'&&a[x+'0'][y+'0'][o+'0']!=1)
{
x=x;y=y-1;
if(x>=0&&x<=m&&y>=0&&y<=n)
continue;
else
{
x=x;y=y+1;c=1;
a[x+'0'][y+'0'][o+'0']=1;
break;
}
}
}
else if(o=='E')
{
if(b=='L')
o='N';
else if(b=='R')
o='S';
else if(b=='F'&&a[x+'0'][y+'0'][o+'0']!=1)
{
x=x+1;y=y;
if(x>=0&&x<=m&&y>=0&&y<=n)
continue;
else
{
x=x-1;y=y;c=1;
a[x+'0'][y+'0'][o+'0']=1;
break;
}
}
}
else if(o=='W')
{
if(b=='L')
o='S';
else if(b[i]=='R')
o='N';
else if(b[i]=='F'&&a[x+'0'][y+'0'][o+'0']!=1)
{
x=x-1;y=y;
if(x>=0&&x<=m&&y>=0&&y<=n)
continue;
else
{
x=x+1;y=y;c=1;
a[x+'0'][y+'0'][o+'0']=1;
break;
}
}
}
}
if(c==1)
printf("%d %d %c LOST\n",x,y,o);
else
printf("%d %d %c\n",x,y,o);
}
return 0;
}
please help...
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA(118 - Mutant Flatworld Explorers)

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
kurmi
New poster
Posts: 1
Joined: Sun Nov 27, 2016 9:52 am

Re: 118 - Mutant Flatworld Explorers

Post by kurmi »

Passed all test cases on udebug but still WA.
Please help.

Code: Select all

#include <iostream>
#include <vector>
#include <algorithm>
// #include <utility>
#include <string>
// #include <stack>
using namespace std;
vector<vector<int> > a(51,vector<int>(51));
int lasti=0,lastj=0,lastdir=0;
int y,x;
string ins;
char dirmap(int dir){
	if(dir==0)return 'N';
	if(dir==1)return 'E';
	if(dir==2)return 'S';
	return 'W';
}
int dirm(char dir){
	switch(dir){
		case 'N': return 0;
		case 'E': return 1;
		case 'S': return 2;
		default: return 3;
	}
}
int move(int i,int j,int dir,int k){
	// cout<<i<<' '<<j<<' '<<dir<<endl;
	if(i>x||j>y||i<0||j<0){
		if(a[lasti][lastj]==1)return move(lasti,lastj,dir,k);
		else return 1;
	}

	lasti=i,lastj=j;lastdir=dir;
	if(k==ins.size())return 0;
	if(ins[k]=='L')return move(i,j,(dir-1+4)%4,k+1);
	else if(ins[k]=='R')return move(i,j,(dir+1)%4,k+1);
	else {
		switch(dir){
			case 0: return move(i-1,j,dir,k+1);
			case 1: return move(i,j+1,dir,k+1);
			case 2: return move(i+1,j,dir,k+1);
			default: return move(i,j-1,dir,k+1);
		}
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	cin>>y>>x;
	while(!cin.eof()){
		int c,r;
		char dir;
		cin>>c>>r>>dir;
		r=x-r;
		ws(cin);
		getline(cin,ins);
		int numdir=dirm(dir);
		int lost=move(r,c,numdir,0);
		if(lost){
			a[lasti][lastj]=1;
			cout<<lastj<<' '<<x-lasti<<' '<<dirmap(lastdir)<<" LOST"<<endl;
		}
		else cout<<lastj<<' '<<x-lasti<<' '<<dirmap(lastdir)<<endl;
	}
}
Post Reply

Return to “Volume 1 (100-199)”