题目链接

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

分析:

n个人进行k局比赛,但每局只有两个人能够进行比赛,最后输出来一个人获胜的总概率(即这个人胜利的局数除以他总共参加比赛的局数),如果一个人一次比赛也没有参加,则输出来一个"-"

代码:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n,k,op=0;
while(~scanf("%d",&n)&&n!=0)
{
op++;
scanf("%d",&k);
int i,j;
int sum[105][105]= {0};
for(i=1; i<=k; i++)
{
int a,b;
char ch1[10],ch2[10];
scanf("%d%s%d%s",&a,ch1,&b,ch2);
if((ch1[0]=='p'&&ch2[0]=='r')||(ch1[0]=='s'&&ch2[0]=='p')||(ch1[0]=='r'&&ch2[0]=='s'))///第一个人赢
sum[a][b]++;
else if((ch1[0]=='r'&&ch2[0]=='p')||(ch1[0]=='p'&&ch2[0]=='s')||(ch1[0]=='s'&&ch2[0]=='r'))///第二个人赢
sum[b][a]++;
}
if(op!=1)
printf("\n");
double sum1,sum2,pj;
for(i=1; i<=n; i++)
{
sum1=0.0;
sum2=0.0;
for(j=1; j<=n; j++)
{
if(sum[i][j]!=0||sum[j][i]!=0)///两个人之间有进行比赛
{
sum1+=sum[i][j];
sum2+=sum[j][i];
}
} if(sum1==0&&sum2==0)///表示一个人一次比赛也没有参加
printf("-\n");
else
{
pj=(double(sum1)/double(sum1+sum2));
printf("%.3lf\n",pj);
}
}
}
return 0;
}

HDU 1148 Rock-Paper-Scissors Tournament (模拟)的更多相关文章

  1. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

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

    Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...

  3. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  4. SDUT 3568 Rock Paper Scissors 状压统计

    就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...

  5. FFT(Rock Paper Scissors Gym - 101667H)

    题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...

  6. Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数

    Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...

  7. Gym101667 H. Rock Paper Scissors

    将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...

  8. 【题解】CF1426E Rock, Paper, Scissors

    题目戳我 \(\text{Solution:}\) 考虑第二问,赢的局数最小,即输和平的局数最多. 考虑网络流,\(1,2,3\)表示\(Alice\)选择的三种可能性,\(4,5,6\)同理. 它们 ...

  9. 题解 CF1426E - Rock, Paper, Scissors

    一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...

  10. 1090-Rock, Paper, Scissors

    描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...

随机推荐

  1. 读着读着《构建之法》(Build To Win) 越精神的白雪儿的思考

    哲学家的宗旨是:我思,故我在 科学家的宗旨是:我发现,故我在 工程师的宗旨是:我构建,故我在 ——<工程学--无尽的前沿> 序言:珍惜角色“人”,注重实践“物” <构建之法>, ...

  2. HDFS shell命令行常见操作

    hadoop学习及实践笔记—— HDFS shell命令行常见操作 附:HDFS shell guide文档地址 http://hadoop.apache.org/docs/r2.5.2/hadoop ...

  3. PAT L1-015 跟奥巴马一起画方块

    https://pintia.cn/problem-sets/994805046380707840/problems/994805124398956544 美国总统奥巴马不仅呼吁所有人都学习编程,甚至 ...

  4. gridview 第一行编辑

    <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.c ...

  5. phpisset()和empty()函数区别

    PHP的isset()函数 一般用来检测变量是否设置 格式:bool isset ( mixed var [, mixed var [, ...]] ) 功能:检测变量是否设置 返回值: 若变量不存在 ...

  6. 第73天:jQuery基本动画总结

    一.DOM对象跟jQuery对象相互转换 jQuery对象转换成DOM对象: 方式一:$(“#btn”)[0] 方式二:$(“#btn”).get(0) DOM对象转换成jQuery对象: $(doc ...

  7. 使用android资源

    1.我们可以命名的资源种类有多少? 答: res/anim/ XML文件,它们被编译进逐帧动画(frame by frame animation)或补间动画(tweened animation)对象 ...

  8. Luogu4927 梦美与线段树(线段树+概率期望)

    每个节点被经过的概率即为该区间和/总区间和.那么所需要计算的东西就是每个节点的平方和了.修改对于某个节点的影响是使其增加2sum·l·x+l2x2.那么考虑对子树的影响,其中Σl2是定值,修改后Σsu ...

  9. WordPress忘记密码找回登录密码的四种行之有效的方法

    WordPress忘记密码找回登录密码的四种行之有效的方法 PS:20170214更新,感谢SuperDoge同学提供的方法,登入phpMyAdmin后,先从左边选自己的数据库,然后点上面的 SQL ...

  10. elasticsearch 第五篇(文档操作接口)

    INDEX API 示例: 1 2 3 4 5 PUT /test/user/1 { "name": "silence", "age": 2 ...