1. 程式人生 > >hdu Nothing is Impossible

hdu Nothing is Impossible

      Problem D. Nothing is Impossible

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 262144/262144K (Java/Other)

Total Submission(s) : 10   Accepted Submission(s) : 9

Problem Description

$m$ students, including Kazari, will take an exam tomorrow.
The paper consists of exactly $n$ problems, the $i$-th problem contains $a_i$ correct answers and $b_i$ incorrect answers, i.e. the $i$-th problem contains $a_i + b_i$ candidates in total.
Each student should choose exactly one candidate as answer for each problem. If the answer to a certain problem is correct, then the student will get one point. The student who gets the most points wins.
Students only know the structure of the paper, but they are able to talk with each other during the exam. They decide to choose a subset $S$ of all $n$ problems, and they will only be able to submit answers on these problems.
They want to know the maximum size of $S$ that the winner among them will solve all the problems in $S$ if they take the optimal strategy.



For sample $1$, students can choose $S = \{1\}$,and we need at least $4$ students to guarantee the winner solve the only problem.

For sample $2$, students can choose $S = \{1, 2, 3\}$, and we need at least $24$ students to guarantee the winner solve these three problems, but if $|S| = 4$, we need at least $96$ students, which is more than $50$.

 

 

Input

The first line of the input contains an integer $T$ $(1 \le T \le 100)$ denoting the number of test cases. Each test case starts with two integers $n, m$ $(1 \le n \le 100, 1 \le m \le 10 ^ 9)$, denoting the number of problems and the number of students. Each of next $n$ lines contains two integers $a_i, b_i$ ([b]$1 \le b_i \le 100, a_i = 1$[/b]), indicating the number of correct answers and the number of incorrect answers of the $i$-th problem.

 

 

Output

For each test case, print an integer denoting the maximum size of $S$.

 

 

Sample Input

 

2 3 5 1 3 1 3 1 3 5 50 1 1 1 3 1 2 1 3 1 5

 

 

Sample Output

 

1 3

 

 

Source

2018 Multi-University Training Contest 4

 

大意:有n道題,m個人,給出每道題對的人數和錯的人數,要求一個人求出最多能對幾道。

思路:給出對錯人數其實是給這道題對的概率,把各題概率排序,由大到小相乘,每次相乘後乘總人數判斷是否大於一個人。然後輸出題的數目就行了。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
    double x;
    double y;
    double z;
} p[10000];
double cmp(node &a,node &b)
{
    if(a.z==b.z)
        return a.y<b.y;
    return a.z>b.z;
}
int main()
{
    long long int t,n,m,k,i,j;
    scanf("%lld",&t);
    while(t--)
    {
        k=1;
        scanf("%lld%lld",&n,&m);
        for(i=0; i<n; i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            p[i].z=p[i].x*1.0/(p[i].x+p[i].y);
        }
        sort(p,p+n,cmp);
        double s=m*1.0*p[0].z;
        for(i=1; i<n; i++)
        {
            if((int)s<=p[i].y)
            {
                break;
            }
            s=s*p[i].z;
            k++;
        }
        printf("%lld\n",k);
    }
    return 0;
}