2018 Multi-University Training Contest 4 D(Nothing is Impossible)

Problem Description
m students, including Kazari, will take an exam tomorrow.
The paper consists of exactly n problems, the i-th problem contains ai correct answers and bi incorrect answers, i.e. the i-th problem contains ai+bi 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≤T≤100) denoting the number of test cases.
Each test case starts with two integers n,m (1≤n≤100,1≤m≤109), denoting the number of problems and the number of students. Each of next n lines contains two integers ai,bi (1≤bi≤100,ai=1), 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
题意:有n道题,m个学生,第i个题有1个正确答案bi个错误答案,每个学生答对一道题获得1分,获得分数最高的学生获胜,但m个学生是一个团队,他们集体会按照某种策略做题,使得有人的分数尽可能大。他们是同时做完题目集体交卷之后才知道正确答案和分数,而正确答案是不确定的。他们策略就是在m的限制下选择一个题目的集合S,使得能够通过分配每个人的选项使得将这个集合的题目全部做对,而集合之外的题目是否有人做对无法保证,所以不予考虑。

思路:因为学生只知道题目有几道对,几道错,为了确保更多的做题数,像一道题只要保证做的学生多于错误选项就至少有一个做对。其实这道题你可以想象成一棵树,每一层的子节点有(xi+yi)条,其中只有xi条是正确的,如果保证学生有人保证有人做对k道题,那么必须保证(x1+y1)...(xk+yk)个情况中全部k题做对的只有x1*x2*...xk种,所以只要人数m>=fun1-fun2+1就可以了。

struct point{
    long long x;
    long long y;
    bool operator <(const point &b)const{
        if ((x+y)!=(b.x+b.y))return x+y<b.x+b.y;
        else return y<b.y;
    }
}p[110];
int main(){
    long long t;
    long long n,m;
    long long i;
    scanf("%lld",&t);
    while (t--){
        scanf("%lld%lld",&n,&m);
        for (i=1;i<=n;i++)scanf("%lld%lld",&p[i].x,&p[i].y);
        sort (p+1,p+n+1);
        long long fun1=1;
        long long fun2=1;
        long long ans=0;
        for (i=1;i<=n;i++){
            fun1=fun1*(p[i].x+p[i].y);
            fun2=fun2*p[i].x;
            if (fun1-fun2+1<=m){
                ans++;
            }
            else break;
        }
        printf("%lld\n",ans);

    }
}

猜你喜欢

转载自blog.csdn.net/snayf/article/details/81394462