题目链接

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. [Oracle收费标准]

    http://www.oracle.com/us/corporate/pricing/technology-price-list-070617.pdf 1: 数据库 2. 中间件 3. weblogi ...

  2. 将Python项目生成所有依赖包的清单requirements .txt文件

    在开发中不同的项目总会牵扯到各种不同作用的包安装,下面是总结一下对写好的项目自动生成依赖清单,以及在新环境下解决依赖的方法: 一:生成所有依赖清单requirements.txt 这里需要使用到的工具 ...

  3. phaser2 微信小游戏入手

    phaser2小游戏基本没什么什么问题,可以下常开发游戏.如果遇到什么问题, 可以提出来共同讨论. 下面来个例子 import './lib/weapp-adapter'; import Phaser ...

  4. sublime py不能输入中文

    设置环境变量PYTHONIOENCODING=UTF-8,重启sublime即可 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/

  5. 在DBGrid中实现多选功能

    1.首先把DBGrid->options-dgMulitSelect设为True.  dgRowSelect也设为True,此属性设为true后,DBGrid将不能编辑,如何实现能否编辑代码如下 ...

  6. linux下面Zookeeper的单机模式(standalone)

    1.下载 zk下载地址 http://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 我用的是http://mirrors.tuna.tsinghua.e ...

  7. Fdisk 分区详解

    Fdisk 分区详解 来源 http://blog.itpub.net/20674423/viewspace-722812/ 1.             通过Fdisk查看系统分区详细信息: Fdi ...

  8. VSS2005清除管理员密码

    1.下载工具ultraedit 2.登录到服务器,找到VSS库文件夹,data\um.dat 3.复制到自己桌面,用ultraedit打开,进入 引用内容 00000080h: 55 55 03 29 ...

  9. 洛谷 P4503 [CTSC2014]企鹅QQ 解题报告

    P4503 [CTSC2014]企鹅QQ 题目背景 PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即 ...

  10. 【2016北京集训】Mushroom

    Portal --> broken qwq Description 一开始有个蘑菇,蘑菇里面有\(n\)个房间,是一棵有根树,\(1\)号是根,每个房间里面都有杂草,现在要支持以下操作:将某个指 ...