Rock-Paper-Scissors Tournament[HDU1148]

Rock-Paper-Scissors Tournament
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2178 Accepted Submission(s): 693

Problem Description
Rock-Paper-Scissors is game for two players, A and B, who each choose, independently of the other, one of rock, paper, or scissors. A player chosing paper wins over a player chosing rock; a player chosing scissors wins over a player chosing paper; a player chosing rock wins over a player chosing scissors. A player chosing the same thing as the other player neither wins nor loses.
A tournament has been organized in which each of n players plays k rock-scissors-paper games with each of the other players - k games in total. Your job is to compute the win average for each player, defined as w / (w + l) where w is the number of games won, and l is the number of games lost, by the player.

Input
Input consists of several test cases. The first line of input for each case contains 1 ≤ n ≤ 100 1 ≤ k ≤ 100 as defined above. For each game, a line follows containing p1, m1, p2, m2. 1 ≤ p1 ≤ n and 1 ≤ p2 ≤ n are distinct integers identifying two players; m1 and m2 are their respective moves ("rock", "scissors", or "paper"). A line containing 0 follows the last test case.

Output
Output one line each for player 1, player 2, and so on, through player n, giving the player‘s win average rounded to three decimal places. If the win average is undefined, output "-". Output an empty line between cases.

Sample Input
2 4
1 rock 2 paper
1 scissors 2 paper
1 rock 2 rock
2 rock 1 scissors
2 1
1 rock 2 paper
0

Sample Output
0.333
0.667

0.000
1.000

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<fstream>
#include<sstream>
#include<iomanip>
#include <sstream>
using namespace std;

const int N=105;

int player[N][2]; // player[i][0]: win , player[i][1]: lose. 

int n,k;
short judge(string a, string b)
{
    if(a == b)
    {
        return 0;
    }
    short result;
    if(a == "rock")
    {
        if(b == "scissors")
        {
            result = 1;
        }
        else if(b == "paper")
        {
            result = -1;
        }
    }
    else if(a == "scissors")
    {
        if(b == "rock")
        {
            result = -1;
        }
        else if(b == "paper")
        {
            result = 1;
        }
    }
    else
    {
        if(b == "scissors")
        {
            result = -1;
        }
        else if(b == "rock")
        {
            result = 1;
        }
    }
    return result;
}
int main()
{
    short ans;
    string sa,sb;
    int pa,pb;
    bool first = true;
    while(cin>>n && n)
    {
        if(!first)putchar(‘\n‘);
        if(first)first=false;
        memset(player,0,sizeof(player));
        cin>>k;
        while(k--)
        {
            cin>>pa>>sa>>pb>>sb;
            ans = judge(sa,sb);
            if(ans)
            {
                if(ans==1)//win
                {
                    player[pa][0]++;
                    player[pb][1]++;
                }
                else//lose
                {
                    player[pb][0]++;
                    player[pa][1]++;
                }
            }
        }
        for(int i=1; i<=n; i++)
        {
            int total = player[i][0]+player[i][1];
            if(total>0)
            {
                printf("%.3f\n",((float)player[i][0])/total);
            }
            else
            {
                printf("-\n");
            }
        }
    }
    return 0;
}

时间: 2024-08-25 20:32:57

Rock-Paper-Scissors Tournament[HDU1148]的相关文章

SDUT 3568 Rock Paper Scissors 状压统计

就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m)m比较小,也就最多几十吧,将将过 #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cstdlib> #include &

GYM 101667H Rock Paper Scissors(FFT)

题意:给你一个串a,是有R,S,P(石头剪刀布)构成的,然后还有一个序列b是你的出牌顺序,但你可以跳过机器的前x个出牌,从x+1开始出,问你最多赢几次 思路:好烦啊,这个题下午一直不会做,感觉和之前学弟将的一个模糊匹配的很像,但好像也不怎么像,挂机一下午. 这个题其实是利用了卷积的性质,我们先考虑单独的每一个字母,因为我们在卷积的时候不能牵扯其他的字符,如果有其他的字符,就类似于模糊匹配了,那是我们只是用FFT加速多项式乘法,而这道题的FFT其实是用FFT算出对于(FFT后的)第i个位置,我们字

HDOJ(HDU) 2164 Rock, Paper, or Scissors?

Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously chooses one of the three items after counting to three. The game typically lasts a pre-determined number of rounds. The player who wins the most rounds w

HDU 2164 Rock, Paper, or Scissors?

http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously chooses one of the three items after counting to three. The game typically lasts a pre-determined number o

BZOJ 4760 Hoof, Paper, Scissors

普及组dp. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 100050 using namespace std; int n,k,dp[maxn][21][4],p[maxn],map[5][5]; char s[5]; int main() { map[2][1]=map[3][2]=map[1][3]=1; scanf(&qu

bzoj4760[USACO2017 Jan]Hoof,Paper,Scissors

题意:玩n次剪刀石头布,对方每次出什么已经知道了.你出的招数必须是连续的几段(不能超过k+1段),问你最多赢几次.(n<=100000,k<=20) 正常做法:f[i][j][k]表示前i次,分j段,最后一次出的是k(k=0,1,2)时最多赢几次,可以O(nk)解决,转移时看最近一次有没有新分一段即可. 智障做法:我们同样定义f[i][j][k]表示前i次,分j段,最后一次出的是k时最多赢几次,但转移的时候考虑最近的一段,也就是枚举最近的一段是从哪里开始的,那么这就变成了1D1D动态规划,打表

Hoof, Paper, Scissors(USACO)

题目大意: 一种游戏(类似于石头剪刀布):两个人分别给出一个字母,然后比较:H>S,S>P,P>H,我们已知对手的字母顺序,求在前n局中我们最多能赢多少次. 由于出字母的人非常懒,所以开局后会选定一种字母,中途只会改变k次,剩余状态下只会不停重复上一次出的字母,所以请你解决这个问题: 好吧,这道题就是DP题. f[i][j][k]表示出到第i局,改变了j次,目前出的是第k个字母的最多赢的局数. 然后每次DP可以从f[i-1][j][k]和f[i-1][j-1][l(l!=k)]转移 然后

How Much Did It Rain? Winner&#39;s Interview: 1st place, Devin Anzelmo

How Much Did It Rain? Winner's Interview: 1st place, Devin Anzelmo An early insight into the importance of splitting the data on the number of radar scans in each row helped Devin Anzelmo take first place in the How Much Did It Rain? competition. In

POJ 3252 Round Numbers

Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12824   Accepted: 4946 Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors',