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 ...
随机推荐
- 将oracle数据库表使用命令的形式导入到excle文件中 亲测可用!
main.sql 中的代码 set markup html on entmap ON spool on preformat off spool D:\新建文件夹\mick\tables.xls @ge ...
- PHP与类有关的几个魔术方法
与类有关的其他魔术方法 序列化与反序列化技术 含义: 序列化: 就是将一个变量所代表的“内存”数据,转换为“字符串”形式并持久保存在硬盘上的一种做法. 反序列化: 就是将序列化之后保存在硬盘上的“字符 ...
- c# assembly
string path = @"c:\text.dll" Assembly assembly = Assembly.LoadFile(path); path = "MyP ...
- zepto中$.proxy()的到底有多强大?
好吧,其实是标题党了,哈哈,只是想总结一下工作中遇到$.proxy()的用法而已. 一.语法: $.proxy()有两种使用语法 1)$.proxy(fn,context),fn是一个函数,conte ...
- 第119天:移动端:CSS像素、屏幕像素和视口的关系
移动前端中常说的 viewport (视口)就是浏览器显示页面内容的屏幕区域.其中涉及几个重要概念是 dip ( device-independent pixel 设备逻辑像素 )和 CSS 像素之间 ...
- Vue使用,异步获取日期时间后格式成"/Date(1333245600000+0800)/" 转换成正常格式
js从后台mvc中日期获取,结果格式成"/Date(1333245600000+0800)/"了,当然不能这样展显给用户了,要转换,方法如下: function data_stri ...
- 抽屉点赞及jQuery CSS操作
1.需要用到的知识点: CSS处理 $('t1').css('color','red') 点赞: -$('t1').append() -$('t1').remove() -setInterval -o ...
- 【刷题】BZOJ 1180 [CROATIAN2009]OTOCI
Description 给出n个结点以及每个点初始时对应的权值wi.起始时点与点之间没有连边.有3类操作: 1.bridge A B:询问结点A与结点B是否连通. 如果是则输出"no&quo ...
- Last Position of Target
For a given sorted array (ascending order) and a target number, find the first index of this number ...
- bzoj2213: [Poi2011]Difference(思维题)
今天颓了一天T T 这题有两种写法... ①预处理出每种字符在原字符串中的位置,枚举两种字符作为最大值和最小值,把这两种字符的坐标归并排序,把最大值设为1,最小值设为-1,求最大子段和.注意因为 ...