首页 > ACM题库 > HDU-杭电 > HDU 2985-Another lottery [解题报告]HOJ
2014
02-24

HDU 2985-Another lottery [解题报告]HOJ

Another lottery

问题描述 :

Even in times of an economic crisis, people in Byteland still like to participate in lotteries. With a bit of luck, they might get rid of all their sorrows and become rich.

The most popular lottery in Byteland consists of m rounds. In each round, everyone can purchase as many tickets as he wishes, and among all tickets sold in this round, one ticket is chosen randomly, each one with the same probability. The owner of that ticket wins the prize money of this round. Since people in Byteland like powers of 2, the prize money for the winner of round i amounts to 2i Bytelandian Dollars.

Can you determine for each participant in the lottery the probability that he will win more money than anybody else?

输入:

The input consists of several test cases. Each test case starts with a line containing two integers n and m, the number of participants in the lottery and the number of rounds in the lottery. You may assume that 1 ≤ n ≤ 10000 and 1 ≤ m ≤ 30.

The following n lines contain the description of the tickets bought by the participant. The ith such line contains m non-negative integers c1, …, cm, where cj (1 ≤ j ≤ m) is the amount of tickets of round j bought by partipant i. The total number of tickets sold in each round is between 1 and 109.

The input ends with a line containing 2 zeros.

输出:

The input consists of several test cases. Each test case starts with a line containing two integers n and m, the number of participants in the lottery and the number of rounds in the lottery. You may assume that 1 ≤ n ≤ 10000 and 1 ≤ m ≤ 30.

The following n lines contain the description of the tickets bought by the participant. The ith such line contains m non-negative integers c1, …, cm, where cj (1 ≤ j ≤ m) is the amount of tickets of round j bought by partipant i. The total number of tickets sold in each round is between 1 and 109.

The input ends with a line containing 2 zeros.

样例输入:

5 4
3 1 2 3
3 1 2 4
3 1 3 5
4 4 4 0
5 5 0 0
1 1
1
0 0

样例输出:

1 / 4
1 / 3
5 / 12
0 / 1
0 / 1
1 / 1

//BISMILLAHIRRAHMANIRRAHIM
/*
 manus tar shopner soman boro
 Author :: Shakil Ahmed
.............AUST_CSE27.........
 prob   ::
 Type   ::
 verdict::
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <limits.h>
#include <set>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <utility>
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfcs(cs,a) printf("Case %d: %d\n",cs,a)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
#define ff first
#define LL long long
#define ss second
#define rep(i,n) for(i = 0; i < n; i++)
#define REP(i,n) for(i=n;i>=0;i--)
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define ROF(i,a,b) for(int i = a; i >= b; i--)
#define re return
#define QI queue<int>
#define SI stack<int>
#define pii pair <int,int>
#define MAX
#define MOD
#define INF 1<<30
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define memo(a,b) memset((a),(b),sizeof(a))
#define G() getchar()
#define MAX3(a,b,c) max(a,max(b,c))

double const EPS=3e-8;
using namespace std;


template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

// Only Last RounD matter in this Problem
const int N = 10000 ;

LL Player [N];

int n,m;
void solve()
{
       int i,j;
       LL sum = 0,inp;
       for ( i = 0 ; i < n ; i++ )
       {
              for ( j = 0 ; j < m-1 ; j++ ) scanf("%lld",&inp);

              scanf("%lld",&Player[i]);

              sum += Player[i];
       }
       for ( i = 0 ; i < n ; i++) {
       LL g = gcd(Player[i],sum);

       printf("%lld / %lld\n",Player[i]/g , sum/g );
       }
}
int main()
{

    //freopen("in.txt", "r", stdin);
     while ( scanf ("%d %d", &n, &m) && (n + m ))
     {
            solve ();
     }

}

  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  2. 这道题目虽然简单,但是小编做的很到位,应该会给很多人启发吧!对于面试当中不给开辟额外空间的问题不是绝对的,实际上至少是允许少数变量存在的。之前遇到相似的问题也是恍然大悟,今天看到小编这篇文章相见恨晚。

  3. 嗯 分析得很到位,确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样:push时,比较要push的elem和辅助栈的栈顶,elem<=min.top(),则min.push(elem).否则只要push(elem)就好。在pop的时候,比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();},否则{stack.pop();}.

  4. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.