11831 - Sticker Collector Robot

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

Moderator: Board moderators

Post Reply
Scarecrow
Learning poster
Posts: 69
Joined: Wed Oct 19, 2011 9:06 pm

11831 - Sticker Collector Robot

Post by Scarecrow » Thu Jul 12, 2012 2:32 pm

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
Do or do not. There is no try.

Alice_Italy
New poster
Posts: 7
Joined: Thu Sep 20, 2012 6:47 am

Re: 11831 - Sticker Collector Robot

Post by Alice_Italy » Wed Oct 10, 2012 2:42 am

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11831 - Sticker Collector Robot

Post by brianfry713 » Wed Oct 10, 2012 7:01 pm

Check line 55. Input:

Code: Select all

1 2 1
L*
F
0 0 0
Check input and AC output for thousands of problems on uDebug!

lukai
New poster
Posts: 25
Joined: Wed Dec 05, 2012 8:11 pm

11831 - Sticker Collector Robot

Post by lukai » Thu Jan 09, 2014 7:51 pm

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?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11831 - Sticker Collector Robot

Post by brianfry713 » Fri Jan 10, 2014 10:55 pm

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
Check input and AC output for thousands of problems on uDebug!

lukai
New poster
Posts: 25
Joined: Wed Dec 05, 2012 8:11 pm

Re: 11831 - Sticker Collector Robot

Post by lukai » Sat Jan 11, 2014 9:32 am

Thanks :D

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11831 - Sticker Collector Robot

Post by uDebug » Fri Mar 27, 2015 1:51 pm

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 118 (11800-11899)”