Rock-Paper-Scissors Tournament[HDU1148]

时间:2022-04-22 02:12:06

Rock-Paper-Scissors Tournament
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2178 Accepted Submission(s): 693

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

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<fstream>
#include<sstream>
#include<iomanip>
#include <sstream>
using namespace std; const int N=; int player[N][]; // player[i][0]: win , player[i][1]: lose. int n,k;
short judge(string a, string b)
{
if(a == b)
{
return ;
}
short result;
if(a == "rock")
{
if(b == "scissors")
{
result = ;
}
else if(b == "paper")
{
result = -;
}
}
else if(a == "scissors")
{
if(b == "rock")
{
result = -;
}
else if(b == "paper")
{
result = ;
}
}
else
{
if(b == "scissors")
{
result = -;
}
else if(b == "rock")
{
result = ;
}
}
return result;
}
int main()
{
short ans;
string sa,sb;
int pa,pb;
bool first = true;
while(cin>>n && n)
{
if(!first)putchar('\n');
if(first)first=false;
memset(player,,sizeof(player));
cin>>k;
while(k--)
{
cin>>pa>>sa>>pb>>sb;
ans = judge(sa,sb);
if(ans)
{
if(ans==)//win
{
player[pa][]++;
player[pb][]++;
}
else//lose
{
player[pb][]++;
player[pa][]++;
}
}
}
for(int i=; i<=n; i++)
{
int total = player[i][]+player[i][];
if(total>)
{
printf("%.3f\n",((float)player[i][])/total);
}
else
{
printf("-\n");
}
}
}
return ;
}

Rock-Paper-Scissors Tournament[HDU1148]的更多相关文章

  1. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock&period;&lpar;FFT字符串匹配&rpar;

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

  2. SDUT 3568 Rock Paper Scissors 状压统计

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

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

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

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

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

  5. Gym101667 H&period; Rock Paper Scissors

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

  6. 【题解】CF1426E Rock&comma; Paper&comma; Scissors

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

  7. 题解 CF1426E - Rock&comma; Paper&comma; Scissors

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

  8. HDOJ&lpar;HDU&rpar; 2164 Rock&comma; Paper&comma; or Scissors&quest;

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

  9. HDU 2164 Rock&comma; Paper&comma; or Scissors&quest;

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

  10. 1090-Rock&comma; Paper&comma; Scissors

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

随机推荐

  1. &period;NET XML文件增删改查

    查询 采用的是DataSet 的 ReadXML方法. DataSet ds = new System.Data.DataSet(); ds.ReadXml("bdc.xml"); ...

  2. Codeforces Round &num;227 &lpar;Div&period; 2&rpar; E&period; George and Cards 线段树&plus;set

    题目链接: 题目 E. George and Cards time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 ...

  3. linux命令之partprobe

    使用fdisk工具只是将分区信息写入到磁盘,如果需要使用mkfs格式化并使用分区,则需要重新启动系统.partprobe 是一个可以修改kernel中分区表的工具,可以使kernel重新读取分区表而不 ...

  4. solr 学习之简介及安装

    一.solr简介 Solr 是Apache下的一个*开源项目,采用Java开发,它是基于Lucene的全文搜索服务器.Solr提供了比Lucene更为丰富的查询语言,同时实现了可配置.可扩展,并对索 ...

  5. noip第5课资料

  6. C&num;学习笔记-接口与抽象类

    namespace ClassLesson { class Program { static void Main(string[] args) { ); Console.WriteLine(perso ...

  7. buntu12&period;10 64位 &plus; android-ndk-r9 编译ffmpeg遇到的问题

      android-ndk-r8d/build/core/build-binary.mk:41: *** target file `clean' has both : and :: entries.  ...

  8. PyCharm设置python新建文件指定编码为utf-8

    PyCharm新建文件时可以在模板中添加编码字符集为utf-8,新建文件可自动添加了

  9. Robot Framework 使用总结

    最近项目上使用了RF快速实现了一些验收测试的自动化case,感觉不错,很好用,下面就记录一下使用RF实现自动化的过程. 什么是RF? RF是一种测试框架,帮助测试人员在其框架下快速实现验收测试的自动化 ...

  10. 服务器重启之后wdcp打不开【解决】

    service wdapache restart