Page 1 of 1

11831 - Sticker Collector Robot

Posted: Thu Jul 12, 2012 2:32 pm
by Scarecrow
A test I/O set that might help

Input

Code: Select all

5 5 64
N.*..
**#**
..#..
**#**
..*..
FFDDDDDFFEFDFDFDFEEFFFDFFDFFEFFFFDFFFFFFFFDFDFFEFFFFDFFFFEFFFFEF
0 0 0
Output

Code: Select all

9

Re: 11831 - Sticker Collector Robot

Posted: Wed Oct 10, 2012 2:42 am
by Alice_Italy
OMG What's wrong with that code? I keep getting WA for no reason!
I've read it soo many times and it seems absolutely right @__@
Please help!

Code: Select all

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;


int n, m, s;
vector< vector<char> > grid;
int xo, yo;
char ori;
int sti;

void rotate(char orient){
    switch (ori){
            case 'N':
            if (orient == 'D') ori = 'L';
            if (orient == 'E') ori = 'O';
            return;
            break;
            case 'L':
            if (orient == 'D') ori = 'S';
            if (orient == 'E') ori = 'N';
            return;
            break;
            case 'S':
            if (orient == 'D') ori = 'O';
            if (orient == 'E') ori = 'L';
            return;
            break;
            case 'O':
            if (orient == 'D') ori = 'N';
            if (orient == 'E') ori = 'S';
            return;
            break;
    }
}

void move(){
    switch (ori){
            case 'N':
            if (yo > 0){
                if (grid[yo-1][xo] != '#'){
                    yo--;
                    if (grid[yo][xo] == '*') {sti++; grid[yo][xo] = '.';}
                }
            }
            return;
            break;
            case 'L':
            if (xo < n-1){
                if (grid[yo][xo+1] != '#'){
                    xo++;
                    if (grid[yo][xo] == '*') {sti++; grid[yo][xo] = '.';}
                }
            }
            return;
            break;
            case 'S':
            if (yo < n-1){
                if (grid[yo+1][xo] != '#'){
                    yo++;
                    if (grid[yo][xo] == '*') {sti++; grid[yo][xo] = '.';}
                }               
            }
            return;
            break;
            case 'O':
            if (xo > 0){
                if (grid[yo][xo-1] != '#'){
                    xo--;
                    if (grid[yo][xo] == '*') {sti++; grid[yo][xo] = '.';}
                }                
            }
            return;
            break;
    }
}

int main()
{
    while (1){
        sti=0;
        scanf("%d %d %d\n", &n, &m, &s);
        grid.assign(n, vector<char>());
        for (int i = 0; i<n; i++) grid[i].assign(m, '.');
        if (n == 0 && m == 0 && s == 0) break;
        string line;
        for (int i = 0; i<n; i++){
            getline(cin,line);
            for (int j = 0; j<m; j++){
                grid[i][j] = line[j];
                if (line[j] == 'N' || line[j] == 'S' || line[j] == 'L' || line[j] == 'O' ){
                    xo = j;
                    yo = i;
                    ori = line[j];
                }
            }
        }
        string inst;
        getline(cin,inst);
        for (int i = 0; i<inst.size(); i++){
            if (inst[i] == 'D' || inst[i] == 'E') rotate(inst[i]);
            else if (inst[i] == 'F') move();
        }
        
        printf("%d\n", sti);
        
    }
    return 0;
}

Re: 11831 - Sticker Collector Robot

Posted: Wed Oct 10, 2012 7:01 pm
by brianfry713
Check line 55. Input:

Code: Select all

1 2 1
L*
F
0 0 0

11831 - Sticker Collector Robot

Posted: Thu Jan 09, 2014 7:51 pm
by lukai

Code: Select all

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;

typedef vector<char>vc;

int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int row,column,numOfCommands,x,y,tcktNum;
    char position;
    while(cin>>row>>column>>numOfCommands)
    {
        if(!row&&!column&&!numOfCommands)
        {
            return 0;
        }
        vector<vc>arena;
        vc tempvector;
        getchar();
        for(int i=0;i<row;i++)
        {
            string input;
            getline(cin,input);
            for(int j=0;j<(int)input.size();j++)
            {
                if(input[j]=='N'||input[j]=='S'||input[j]=='L'||input[j]=='O')
                {
                    x=i;
                    y=j;
                    position=input[j];
                    input[j]='.';
                }

                tempvector.push_back(input[j]);
            }
            arena.push_back(tempvector);
            tempvector.clear();
        }
        string commands;
        getline(cin,commands);
        tcktNum=0;
        for(int i=0;i<numOfCommands;i++)
        {
            if(commands[i]=='D')
            {
                if(position=='N')
                {
                    position='L';
                }
                else if(position=='L')
                {
                    position='S';
                }
                else if(position=='S')
                {
                    position='O';
                }
                else if(position=='O')
                {
                    position='N';
                }
            }
            else if(commands[i]=='E')
            {
                if(position=='N')
                {
                    position='O';
                }
                else if(position=='O')
                {
                    position='S';
                }
                else if(position=='S')
                {
                    position='L';
                }
                else if(position=='L')
                {
                    position='N';
                }
            }
            else if(commands[i]=='F')
            {


                if(position=='N')
                {
                    if(x-1<0)
                    {
                        continue;
                    }
                    else if(arena[x-1][y]=='#')
                    {
                        continue;
                    }
                    else if(arena[x-1][y]=='.')
                    {
                        x--;
                    }
                    else if(arena[x-1][y]=='*')
                    {
                        tcktNum++;
                        arena[x-1][y]='.';
                        x--;
                    }
                }
                else if(position=='S')
                {
                    if(x+1>row-1)
                    {
                        continue;
                    }
                    else if(arena[x+1][y]=='#')
                    {
                        continue;
                    }
                    else if(arena[x+1][y]=='.')
                    {
                        x++;
                    }
                    else if(arena[x+1][y]=='*')
                    {
                        tcktNum++;
                        arena[x+1][y]='.';
                        x++;
                    }
                }
                else if(position=='L')
                {
                    if(y+1>column-1)
                    {
                        continue;
                    }
                    else if(arena[x][y+1]=='#')
                    {
                        continue;
                    }
                    else if(arena[x][y+1]=='.')
                    {
                        y++;
                    }
                    else if(arena[x][y+1]=='*')
                    {
                        tcktNum++;
                        arena[x][y+1]='.';
                        y++;
                    }
                }
                else if(position=='O')
                {
                    if(y-1<0)
                    {
                        continue;
                    }
                    else if(arena[x][y-1]=='#')
                    {
                        continue;
                    }
                    else if(arena[x][y-1]=='.')
                    {
                        y--;
                    }
                    else if(arena[x][y-1]=='*')
                    {
                        tcktNum++;
                        arena[x][y--]='.';
                        y--;
                    }
                }

            }

        }
        arena.clear();
        cout<<tcktNum<<endl;

    }
    return 0;
}
Why WA?

Re: 11831 - Sticker Collector Robot

Posted: Fri Jan 10, 2014 10:55 pm
by brianfry713
Input:

Code: Select all

4 7 18
*#**..*
#*#*#*.
.**L#..
###***#
FDEEEEDDDFFEFFFDFE
2 1 17
S
#
DDFDFFEDEFDDDDFDF
5 4 11
*.L#
#..#
#*..
#.**
*..#
EFDFFDDEFEF
7 2 6
#*
#*
..
*S
#.
#.
*.
DFEFFF
9 2 13
#.
#.
.*
#*
..
##
*#
N*
##
EFEEFEDEFFDDF
6 10 17
*##*##.*#*
#*.*##....
#***###*O*
....#.#..#
##*#*.###*
.#.#*..*##
DEFEEFEDEEDEFDFED
3 6 9
*.##..
#L.##.
*##.#.
EDEFFEDDE
9 1 16
#
#
#
.
N
#
.
.
.
EDFFEEDDFFDFDDED
2 6 20
N.#**#
##.##.
EFFEDFEDFFEDFEEFFFFF
5 1 10
.
.
*
.
O
FDFDEEEFEE
0 0 0
AC output:

Code: Select all

2
0
0
1
1
1
0
0
0
0

Re: 11831 - Sticker Collector Robot

Posted: Sat Jan 11, 2014 9:32 am
by lukai
Thanks :D

Re: 11831 - Sticker Collector Robot

Posted: Fri Mar 27, 2015 1:51 pm
by uDebug
Replying to follow the thread.