首页 > 其他 > 详细

Another lottery

时间:2014-03-30 09:33:57      阅读:365      评论:0      收藏:0      [点我收藏+]

http://acm.hdu.edu.cn/showproblem.php?pid=2985

题意:有n个人每个人可以买m轮彩票,每轮可以买尽可能多的彩票。如果该彩票在i轮被抽到,则该人可以获得2^i的奖金,问该人获得的奖金数比其他人都高的概率。

思路:如果该人在第m轮中奖,则他获得的奖金数最高,如果m轮没人买彩票,则在m-1轮中奖奖金数最高。。以此类推。。求出在该轮的中奖概率即可。最后的分数输出形式通过最大公约数化简。

bubuko.com,布布扣
 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 }
View Code

Another lottery,布布扣,bubuko.com

Another lottery

原文:http://www.cnblogs.com/lahblogs/p/3633335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!