HDU 1148 Rock-Paper-Scissors Tournament (模拟)
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 (模拟)的更多相关文章
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
- HDOJ(HDU) 2164 Rock, Paper, or Scissors?
Problem Description Rock, Paper, Scissors is a two player game, where each player simultaneously cho ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- SDUT 3568 Rock Paper Scissors 状压统计
就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...
- FFT(Rock Paper Scissors Gym - 101667H)
题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...
- Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数
Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...
- Gym101667 H. Rock Paper Scissors
将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...
- 【题解】CF1426E Rock, Paper, Scissors
题目戳我 \(\text{Solution:}\) 考虑第二问,赢的局数最小,即输和平的局数最多. 考虑网络流,\(1,2,3\)表示\(Alice\)选择的三种可能性,\(4,5,6\)同理. 它们 ...
- 题解 CF1426E - Rock, Paper, Scissors
一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...
- 1090-Rock, Paper, Scissors
描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...
随机推荐
- Halcon 笔记3 形态学
Halcon 三大数据类型: (1)图像 (2)区域 (3)XLD 查看时间工具 如果想让图像减少,则进行腐蚀(或者使用开运算),反之,则进行膨胀(或闭运算) 腐蚀后再进行膨胀,相当于进行开运算.因 ...
- PHP之implode()方法
implode — 将一个一维数组的值转化为字符串 string implode ( string $glue , array $pieces ) string implode ( array $pi ...
- postgis_LayerTransform
[转] postgis_LayerTransform 一个在postgis中结合中国国情,批量对数据进行加偏到百度坐标,高德谷歌的火星坐标,或者逆向纠偏 安装: 在postgresql-postgis ...
- brush
简介 Brushing是一个通过点击或触摸来选择一个一维或二维区域的交互操作,比如可以通过点击鼠标并移动. brush经常被用来选择离散的元素比如散点图中的点或桌面上的文件等.它也可以被用来放大选中的 ...
- 第180天:HTML5——本地存储
本地存储 客户端存储数据的方法 cookie 方法 localStorage方法 sessionStorage方法 一.localStorage 1.存储特点: localStorage方法存储的数据 ...
- BZOJ 4034 树上操作(树的欧拉序列+线段树)
刷个清新的数据结构题爽一爽? 题意: 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x ...
- 洛谷 P2146 [NOI2015]软件包管理器
真没有想到,这竟然会是一道NOI的原题,听RQY说,这套题是北大出的,北大脑抽认为树剖很难... 只恨没有早学几年OI,只A这一道题也可以出去吹自己一A了NOI原题啊 好了,梦该醒了,我们来看题 以后 ...
- Frequent values UVA - 11235(巧妙地RMQ)
题意: 给出一个非降序排列的整数数组a1.a2,······,an,你的任务是对于一系列询问(i,j),回答ai,ai+1,······,aj中出现次数最多的值所出现的次数 解析: 白书p198 其实 ...
- 【刷题】BZOJ 1211 [HNOI2004]树的计数
Description 一个有n个结点的树,设它的结点分别为v1, v2, -, vn,已知第i个结点vi的度数为di,问满足这样的条件的不同的树有多少棵.给定n,d1, d2, -, dn,编程需要 ...
- 利用MSXSL.exe绕过AppLocker应用程序控制策略
1.需要用到微软工具MSXSL.exe,msxsl.exe是微软用于命令行下处理XSL的一个程序,所以通过他,我们可以执行JavaScript进而执行系统命令,其下载地址为: https://www. ...