10903 - Rock-Paper-Scissors Tournament

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

Moderator: Board moderators

Monsoon
Learning poster
Posts: 66
Joined: Fri Jul 23, 2004 4:42 pm
Location: Poland

Post by Monsoon »

read once again problem statement and how many there are games to read?
Cezary Zukowski
New poster
Posts: 5
Joined: Tue Oct 12, 2004 1:42 am
Location: Poland

Post by Cezary Zukowski »

Yes, there aren't k games in total but k*n*(n-1)/2 games in total. I have got AC. Thanks.
Soarer
New poster
Posts: 14
Joined: Wed Nov 09, 2005 8:17 pm

Post by Soarer »

I received a presentation error, but I don't know why. Can anyone help?

Code: Select all

        #include <iostream>
        #include <string>
        #include <iomanip>
        
        using namespace std;
        
        int main(){
               int num_of_players = 1, games_per_player, num_of_games;
               while(true){
               cin >> num_of_players;
               if(num_of_players == 0)
               break;
               cin >> games_per_player;
               
               
               num_of_games = games_per_player * num_of_players * (num_of_players - 1) / 2;
               
               int win[num_of_players], game[num_of_players];
               
               for(int i = 0; i < num_of_players; i++){
                       win[i] = 0;
                       game[i] = 0;
               }
               
               int count = 0;
               int play_1 = 1, play_2;
               char game_1[10], game_2[10];
               
               while(count < num_of_games && play_1 != 0){                 
                  cin >> play_1 >> game_1 >> play_2 >> game_2;
                  if((game_1[0] == 'r' && game_2[0] == 'p') || (game_1[0] == 'p' && game_2[0] == 's') || (game_1[0] == 's' && game_2[0] == 'r')){
                           win[play_2 - 1] += 1;
                           game[play_2 - 1] += 1;
                           game[play_1 - 1] += 1;        
                  }
                  else if((game_2[0] == 'r' && game_1[0] == 'p') || (game_2[0] == 'p' && game_1[0] == 's') || (game_2[0] == 's' && game_1[0] == 'r')){
                           win[play_1 - 1] += 1;
                           game[play_1 - 1] += 1;
                           game[play_2 - 1] += 1;   
                          }
                  else{
                  }
                  cout.flush();
                  count++;
               }
               
               for(int j = 0; j < num_of_players; j++){
                       if(game[j] == 0)
                       cout << "-" << endl;
                       else
                       cout << setiosflags ( ios::showpoint | ios::fixed ) << setprecision(3) << win[j]/double(game[j]) << endl;
               }
               cout << endl;
             }
             return 0;
        }
      
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

Presentation Error usually causes due to extra line in the output. In this problem you aren't supposed to print a blank line after the last case.
Soarer
New poster
Posts: 14
Joined: Wed Nov 09, 2005 8:17 pm

Post by Soarer »

Thanks! I've fixed the problem. :D
ankit.arora
New poster
Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India

Post by ankit.arora »

i am getting WA but everything seems to be all right in my code.....
please if anyone can give me few test cases so that i am able to fix it.
Thanks!
Fuad Hassan EWU
New poster
Posts: 38
Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University

can't find the bug

Post by Fuad Hassan EWU »

Hi, this code is giving me WA :oops: . where is the bug :evil: ? plz help. thanks :lol:

Code: Select all

found the bug,trying to fix it. fixing in process....

Finally got AC
Eagle er moto daana meley urbo
sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

Post by sapnil »

Try this case:

Code: Select all

Input:
2 12
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
2 8
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
Output:
0.333
0.667

0.333
0.667
Thanks
Keep posting
Sapnil
Mata
New poster
Posts: 18
Joined: Mon Dec 17, 2007 11:35 pm
Location: Queretaro
Contact:

help! please

Post by Mata »

hi, i tried this problem but i just get Wa, if someone have some input so i can find my mistake.
thanks.
here is my code

Code: Select all

got Ac
Last edited by Mata on Mon Dec 24, 2007 8:04 pm, edited 1 time in total.
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

Your code is overflowing when the input is "scissors".

-----
Rio
Mata
New poster
Posts: 18
Joined: Mon Dec 17, 2007 11:35 pm
Location: Queretaro
Contact:

Post by Mata »

Thanks, I didn't notice it, now i got Ac
sreejond
New poster
Posts: 32
Joined: Fri May 23, 2008 6:16 pm
Contact:

Re: 10903 - Rock-Paper-Scissors Tournament

Post by sreejond »

ac
Last edited by sreejond on Thu Jun 04, 2009 2:39 pm, edited 1 time in total.
x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Re: 10903 - Rock-Paper-Scissors Tournament

Post by x140l31 »

I was :o when I got TLE...

Code: Select all

#include <iostream>
#include <vector>
using namespace std;

typedef vector<int> VI;

int main()
{
    cout.setf(ios::fixed);
    cout.precision(3);
    int n, k, first = 1;
    while (cin >> n and n)
    {
        if (not first) cout << endl;
        first = false;
        cin >> k;
        int gam = k*n*(n - 1)/2;
        VI win(n + 1), lose(n + 1);
        while (gam--)
        {
            int p1, p2;
            string act1, act2;
            cin >> p1 >> act1 >> p2 >> act2;
            if (act1 == "rock")
            {
                if (act2 == "scissors") { win[p1]++; lose[p2]++; }
                else if (act2 == "paper") { win[p2]++; lose[p1]++; }
            }
            else if (act1 == "scissors")
            {
                if (act2 == "paper") { win[p1]++; lose[p2]++; }
                else if (act2 == "rock") { win[p2]++; lose[p1]++; }
            }
            else
            {
                if (act2 == "rock") { win[p1]++; lose[p2]++; }
                else if (act2 == "scissors") { win[p2]++; lose[p1]++; }
            }
        }

        for (int i = 1; i <= n; i++)
        {
            double w = win[i], l = lose[i];
            if (w or l) cout << w/(w + l) << endl;
            else cout << '-' << endl;
        }
    }
}
there's any bug?
sp2hari
New poster
Posts: 3
Joined: Sun Nov 09, 2008 10:56 pm

Re: 10903 - Rock-Paper-Scissors Tournament

Post by sp2hari »

Can anyone explain the output for the following input? I got the output from uvatoolkit.com.

Code: Select all

2 2
1 rock 2 paper
2 rock 1 paper
3 2
1 rock 2 paper
2 rock 1 paper
0

Code: Select all

0.500
0.500

0.833
0.500
-
Why is there a difference in the values in the first and the second case?
sp2hari
New poster
Posts: 3
Joined: Sun Nov 09, 2008 10:56 pm

Re: 10903 - Rock-Paper-Scissors Tournament

Post by sp2hari »

sreejond wrote:hello,
i try this problem long time ago & still got WA.
Can enyone help me?
Where is my BUG?

here is my code:
Hi, sreejond,
I haven't seen your entire code, but just check this part

Code: Select all

 
        if(r1==0.0 && r2==0.0)
         {
            printf("-\n");
            break;
         }
I think it should be a continue instead of break I guess. If the first player has an invalid win average, then it is not printing the rest of the players.
Post Reply

Return to “Volume 109 (10900-10999)”