http://acm.hdu.edu.cn/showproblem.php?pid=2985
题意:有n个人每个人可以买m轮彩票,每轮可以买尽可能多的彩票。如果该彩票在i轮被抽到,则该人可以获得2^i的奖金,问该人获得的奖金数比其他人都高的概率。
思路:如果该人在第m轮中奖,则他获得的奖金数最高,如果m轮没人买彩票,则在m-1轮中奖奖金数最高。。以此类推。。求出在该轮的中奖概率即可。最后的分数输出形式通过最大公约数化简。
1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 #define LL __int64 5 using namespace std; 6 const int N=10010; 7 LL a[N][32]; 8 LL p[N]; 9 int main() 10 { 11 int n,m; 12 while(~scanf("%d%d",&n,&m)) 13 { 14 LL sum = 0; 15 if (n==0&&m==0) 16 break; 17 for (int i = 0; i < n; i++) 18 { 19 for (int j = 0; j < m; j++) 20 { 21 scanf("%I64d",&a[i][j]); 22 } 23 } 24 while(!sum) 25 { 26 for (int i = 0; i < n; i++) 27 { 28 sum+=a[i][m-1]; 29 p[i] = a[i][m-1]; 30 } 31 m--; 32 } 33 for (int i = 0; i < n; i++) 34 { 35 LL temp = __gcd(sum,p[i]); 36 LL r1 = p[i]/temp; 37 LL r2 = sum/temp; 38 printf("%I64d / %I64d\n",r1,r2); 39 } 40 } 41 return 0; 42 }
Another lottery,布布扣,bubuko.com
原文:http://www.cnblogs.com/lahblogs/p/3633335.html