10443 - Rock

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

Moderator: Board moderators

lonelyone
Learning poster
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Post by lonelyone »

Ryan Pai wrote:For each string you're only allocating c characters. You need one more for the null terminator.

You also don't free the memory you malloc, so there's a leak.

I'd suggest using a static two dimensional array insead.
Thank you, you are a nice guy :D
but could you explain this problem for me...
i can't realize it completely...
and my code got wrong answer again... :cry:
lonelyone
Learning poster
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Post by lonelyone »

Code: Select all

INPUT
1 10 4 
SRPSRPPRSR 

OUTPUT
RPPPPPPPPP 
RPPPPPPPPP is right..
but my output is RPPPPPPPRR
WHY....??
Could someone explain it in detail..
lonelyone
Learning poster
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Post by lonelyone »

lonelyone wrote:

Code: Select all

INPUT
1 10 4 
SRPSRPPRSR 

OUTPUT
RPPPPPPPPP 
RPPPPPPPPP is right..
but my output is RPPPPPPPRR
WHY....??
Could someone explain it in detail..
Ok!!
i got a.c.

thank anyone who take a view in this article..
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

10443

Post by IRA »

3 4 2
RSPR
SPRS
PRSP

Who can tell me the data how to change in first day and second day?
Thanks in advance
neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci »

After day #1:

Code: Select all

RRSP
RSPR
SPRS
After day #2:

Code: Select all

RRRS
RRSP
RSPR
good luck..., Yandry.
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA »

neno_uci wrote:After day #1:

Code: Select all

RRSP
RSPR
SPRS
After day #2:

Code: Select all

RRRS
RRSP
RSPR
good luck..., Yandry.
How to change the data become the first day?
I can't think about it.
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA »

neno_uci wrote:After day #1:

Code: Select all

RRSP
RSPR
SPRS
After day #2:

Code: Select all

RRRS
RRSP
RSPR
good luck..., Yandry.
How to change the data become the first day?
I can't think about it.
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

10443,wa ples help!!!!

Post by turcse143 »

this is sample input output whats problem ples give any logic
intput:
6
0 0 3

1 1 3
R
1 10 4
SRPSRPPRSR
10 1 4
R
S
P
P
S
R
R
S
P
P
3 4 3
PRSP
RSPR
SPRS
5 5 5
RRRSP
RSRSP
RRRRP
SRRRP
RPPRP

output:


R

RPPPPPPPPP

R
R
R
R
R
R
R
R
R
R

PPPP
PPPR
PPRS

RRRRR
RRRRR
PPPPP
PPPPP
PPPPP

Press any key to continue
whats problem???
''I want to be most laziest person in the world''
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 »

i have problem in the output
here:
RRRRR
RRRRR
PPPPP
PPPPP
PPPPP

by using dufferent logic i got accept
...use double array
...check every possible ocurrence
''I want to be most laziest person in the world''
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Re: 10443 - Rock, Scissors, Paper

Post by stcheung »

This problem is one of the most straightforward ones I have seen, so if you are struggling then you are probably doing something wrong. In that case see if the following hints help:

(1) As someone mentioned before, it's probably easier to figure out how a given cell will change based on its neighboring cells than to figure out the opposite. More explicitly, if the current cell is Scissors, it will be a Rock only if one of its neighbors is a Rock.

(2) Like many other problems, if you are storing data for a r-by-c grid, you might want to define char [r+2][c+2] instead of char [r][c] and store the data in the middle so that you don't have to do all the boundary checking. I find this quite helpful, especially for all those problems involving chessboards.

(3) Really can't think of any other tip. Just make sure you output a blank line BETWEEN cases.
MEGADEEN
New poster
Posts: 5
Joined: Sun Jun 15, 2014 9:26 am

10443 - Rock

Post by MEGADEEN »

I tried testing my code with self-created test cases and it seems to work fine but I keep on getting WA. What is wrong with my code?
Thank you for helping.

Code: Select all

#include <iostream>
using namespace std;

int r, c, n;
char original[101][101], duplicate[101][101];

bool winner(char y, char x) {
    if (x == 'R' && y == 'S')
        return true;
    if (x == 'S' && y == 'P')
        return true;
    if (x == 'P' && y == 'R')
        return true;
    return false;
}

void battle (int i, int j) {
    bool defeat;
    if (j < c - 1) { // if not last column, combat with right side
        defeat = false;
        defeat = winner(original[i][j], original[i][j + 1]);
        if (defeat) {
            duplicate[i][j] = original[i][j + 1];
            return;
        }
    }

    if (j > 0) { // if not first column, combat with left side
        defeat = false;
        defeat = winner(original[i][j], original[i][j - 1]);
        if (defeat) {
            duplicate[i][j] = original[i][j - 1];
            return;
        }
    }

    if (i != 0) { // if not first row, combat with top
        defeat = false;
        defeat = winner(original[i][j], original[i - 1][j]);
        if (defeat) {
            duplicate[i][j] = original[i - 1][j];
            return;
        }
    }

    if (i < r - 1) { // if not last row, combat with bottom
        defeat = false;
        defeat = winner(original[i][j], original[i + 1][j]);
        if (defeat) {
            duplicate[i][j] = original[i + 1][j];
            return;
        }
    }

    duplicate[i][j] = original[i][j];
    return;
}

int main() {
    int tc;
    cin >> tc;
    
    while (tc--) {
        cin >> r >> c >> n;

        cin.ignore();

        for (int i = 0; i < r; ++i) {
            cin.getline(original[i], 100);
        }

        for (int i = 0; i < n; ++i) {
            for (int m = 0; m < r; ++m) {
                for (int n = 0; n < c; ++n) {
                    battle(m, n);
                    //cout << duplicate[m][n];
                }
                //cout << endl;
            }

            for (int m = 0; m < r; ++m) {
                for (int n = 0; n < c; ++n) {
                    original[m][n] = duplicate[m][n];
                }
            }
        }

        for (int i = 0; i < r; ++i) {
            for (int j = 0; j < c; ++j) {
                cout << original[i][j];
            }
            cout << endl;
        }

        if (tc)
            cout << endl;
    }

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

Re: 10443 - Rock, Scissors, Paper

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 104 (10400-10499)”