题意:
这里是给出2*n张牌,每张牌的值都不一样,A,B两个人任意从中选出1张牌,之后将这2张牌给丢弃,其中谁的牌越大的话,其就得一分
现在问你,A获得分数的期望是多少
题解:
首先我们有2*n张牌,最优的得分是n->A抽出最大的n张
最差的得分是0->A抽出最小的n张
所以对于A来说,A能获得的分的期望是 (n+0) / 2
其实这里的期望可以看成平均值.概率相等.
则综上很好写出代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 10000100; bool vis[maxn]; int main() { int caset,cas=0;scanf("%d",&caset); while(caset--) { int n;scanf("%d",&n); for(int i=0,x;i<2*n;i++) scanf("%d",&x); printf("Case %d: %.2f\n",++cas,1.0*n/2); } return 0; }