题目链接

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. 关于“问吧APP”问卷调查报告分析与体会

         上周根据我们走廊奔跑队的“问吧APP”项目对本校范围内的学生发放了上百份调查问卷,并对此作出了统计和整理.针对我们项目所提出的问题涉及到的用户信息有性别.年龄.学历.职业.平时上网途径以及对 ...

  2. Objective - C 之类目

    一.类目(category):为已有的类(可以是系统类,也可以是自定义类)添加公有的新的方法: 例如:为系统已有的NSString类添加一个比较字符串大小的方法 1.创建过程: 2.NSString ...

  3. week1词频统计

    使用java完成对txt格式的英文短片进行字符提取及统计. package nenu.softWareProject; import java.io.*;import java.util.*; pub ...

  4. ci上传图片

    o_upload.php <?php /** * Created by PhpStorm. * User: brady * Date: 2018/3/15 * Time: 14:10 */ cl ...

  5. 在线webservice

    腾讯QQ在线状态 WEB 服务Endpoint: http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx Disco: http:// ...

  6. react-router之代码分离

    概念 无需用户下载整个应用之后才能访问访问它.即边访问边下载.因此我们设计一个组件<Bundle>当用户导航到它是来动态加载组件. import loadSomething from 'b ...

  7. LoadRunner脚本增强技巧之参数化(二)

    特别提醒: 1.在形成数据池之后,数据库中的数据变化不会影响数据池中的数据. 2.数据文件一定要以一个空行结束,否则,最后一行输入的数据不会被参数所使用. 3.一般我们用到的很多的都是使用数据文件来保 ...

  8. 【BZOJ1951】古代猪文(CRT,卢卡斯定理)

    [BZOJ1951]古代猪文(CRT,卢卡斯定理) 题面 BZOJ 洛谷 题解 要求什么很显然吧... \[Ans=G^{\sum_{k|N}{C_N^k}}\] 给定的模数是一个质数,要求解的东西相 ...

  9. CF954F Runner's Problem(动态规划,矩阵快速幂)

    CF954F Runner's Problem(动态规划,矩阵快速幂) 题面 CodeForces 翻译: 有一个\(3\times M\)的田野 一开始你在\((1,2)\)位置 如果你在\((i, ...

  10. 框架----Django内置Admin

    Django内置的Admin是对于model中对应的数据表进行增删改查提供的组件,使用方式有: 依赖APP: django.contrib.auth django.contrib.contenttyp ...