第七届福建省大学生程序设计竞赛
Problem 2264 Card Game (First Edition)
题意:
有2×n张牌,Fat brother 和 Maze两个人轮流取一张牌,不放回, 谁取的牌大谁就得一分。问Fat brother 得分的期望。
题解:
每个人赢的概率都是0.5。
代码:
#include<stdio.h> using namespace std; int main(){ int T; scanf("%d",&T); for(int t = 1; t <= T; t++) { int n,x; scanf("%d",&n); for (int i = 0; i < n*2; i++){ scanf("%d",&x); } printf("Case %d: %.2f ",t,n/2.0); } return 0; }
Problem 2265 Card Game (Second Edition)
题意:
Fat brother 和 Maze两个人分别有n张牌,每轮两个人都在自己的牌里面随便选一张,不放回, 谁取的牌大谁就得一分。问Fat brother 得分的期望。
题解:
将Fat brother每张牌能赢的次数加起来除以n。排个序在找就行了。
代码:
#include<stdio.h> #include<algorithm> using namespace std; const int N = 10000 + 10; int a[N],b[N]; int main(){ int T,n; scanf("%d",&T); for(int t = 1; t <= T; t++) { scanf("%d",&n); for (int i = 0; i < n; i++){ scanf("%d",&a[i]); } for (int i = 0; i < n; i++){ scanf("%d",&b[i]); } sort(a,a+n); sort(b,b+n); int cnt = n-1,sum = 0; for (int i = n-1; i >=0; i--){ while(a[i]<=b[cnt] && cnt>=0) cnt--; if (cnt<0) break; if (a[i] > b[cnt]) sum+=cnt+1; } printf("Case %d: %.2f ",t,(double)sum/(double)n); } return 0; }