水题,统计每个人输赢次数lost[i]和win[i],如果lost[i]+win[i]=0说明此人未参加比赛,胜率不确定
,否则win[i]/(win[i]+lost[i])为该人胜率
Solution:
#include <algorithm> #include <iostream> #include <utility> #include <cstring> #include <cstdlib> #include <cstdio> #include <string> #include <vector> #include <cmath> #include <queue> #include <map> using namespace std; #define mm(a) memset(a, 0, sizeof(a)) #define LL long long #define Mod 1000000007 bool flag; int i,j,n,k; string s; int a,b; int t=0; int win[105]={0}; int lose[105]={0}; int main() { // freopen("E:\\input.txt","r",stdin); // cout<<"t:"<<t<<endl; while(1) { scanf("%d", &n); if(n==0) break; mm(win),mm(lose); if(t++) printf("\n"); scanf("%d", &k); for(i=0; i<k*n*(n-1)/2; i++) { int p1=0,p2=0; char s1[10]= {0},s2[10]= {0}; scanf("%d %s %d %s", &p1, s1, &p2, s2); if(s1[0] == s2[0]) continue; else if(s1[0]=='r'&&s2[0]=='s' || s1[0]=='s'&&s2[0]=='p' || s1[0]=='p'&&s2[0]=='r') {win[p1]++;lose[p2]++;} else {win[p2]++;lose[p1]++;} } for(int i=1; i<=n; i++) // cout<<p[i].w<<":"<<p[i].l<<endl; if(win[i]+lose[i])printf("%.3f\n",1.0*win[i]/(win[i]+lose[i])); else printf("-\n"); // printf("\n"); } return 0; }