Welcome

首页 / 软件开发 / 数据结构与算法 / HDU 2985 Another lottery(水题)

HDU 2985 Another lottery(水题)2015-02-17HDU 2985:http://acm.hdu.edu.cn/showproblem.php?pid=2985

大意:

给你n个人,每个人买m次彩票,第i次的奖金是2的i次方,求每个人赢的比其他人都多的可能性是多少。

思路:

就是只看最后一次就行,2的i次方,对于每个人来说,最后一次的奖要比前面的大很多,所以直接只看最后一次,算出概率gcd一下就行了。

#include <stdio.h>#include <string.h>int a[10010];int gcd(int a, int b){return b > 0 ? gcd(b, a%b) : a;}int n, m;void Solve(){while(~scanf("%d%d", &n, &m)){if(!n && !m){break;}int sum = 0;for(int i = 0; i < n; ++i){for(int j = 0; j < m; ++j){scanf("%d", &a[i]);}sum += a[i];}for(int i = 0; i < n; ++i){int t = gcd(sum, a[i]);//printf("%d
", t);printf("%d / %d
", a[i]/t, sum/t);}}}int main(){Solve();return 0;}
From:cnblogs GLSilence