HDU 6335 Problem D. Nothing is Impossible (2018 Multi-University Training Contest 4)

Problem D. Nothing is Impossible

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 520    Accepted Submission(s): 308


 

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

扫描二维码关注公众号,回复: 8833141 查看本文章

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

题目大意:

给你t组数据,每组数据的第一行有两个数n和m,然后接下来有n行,每行有2个数字ai和bi。代表有n道题目,每一道题目正确的个数是ai个,错误的个数是bi个。然后有m个可以互相沟通的人,他们的集体荣誉感非常的强,他们有策略的选择,想让其中一个人获得最高的分数,现在让你计算他们在最坏的情况下的最高分数是多少。

解法:

题目的意思并不是所有的题目都要选择,他们是有策略的选择,保证有人获得最大的分数值,并且是在最坏的情况下。可能很多人没有看懂样例,看懂了样例,这道题其实非常的简单,说是一道水题也不为过。

第一组样例:

3 5

1 3

1 3

1 3

他们只选择第一组进行答题,那么他们只需要4个人去试一遍四个选项,就能让其中一个人获得最高的分数值。由于是最坏的情况,所以即使他们其中一个获得1分的人继续往下选择其余两道题,也不能拿到两分。(没听懂的可以看我解释第二组样例)

第二组样例:

5 50

1 1

1 3

1 2

1 3

1 5

首先他们选择的是概率最大的第一题去回答,有1/2的概率会答对,按理说我们只需要2个人就可以试出答案,但是因为我们足足有50个人,所以我们可以继续往下试答案(为什么呢,往下看就知道了),第二题我们选择概率为1/3的题目。要答对这道题,按理说我们只需要3个人就能试出正确答案,但是为了确保答对第一题的人能答对第二题,使得分值最大化,我们答第一题的时候不能只是2个人,2个人是不能确保答对第一题的人能答对第二题,要使得答对第一题的人去答对第二题,那么答对第一题的人至少要有3个人,让这3个人分别的去试这3个选项,就一定能保证有人能拿到两分。因为我们不能保证第一题的答案是哪一个,所以我们需要2*3个人去分别试两个选项。所以要得到两分我们需要6个人,人数还是很充裕,我们可以继续选择下一题,概率为1/4的题目,这道题同样的,按照之前的方法就是2*3*4个人去试答案,能确保一个人能拿到3分。当我们想继续得第四分的时候,2*3*4*4=96远远大于50个人,并且是在最坏情况,所以他们是不可能蒙对其他题目使得分值最大化~

附上AC代码:

#include <bits/stdc++.h>
using namespace std;
int cmp(int x,int y){return x<y;}
int main(){
	int t,a,b,n,m,num[105];
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&m);
		for(int i=0;i<n;i++){
			scanf("%d%d",&a,&b);
			num[i]=a+b;
		}
		long long sum=0,number=-1,i;
		sort(num,num+n,cmp);
		for(i=0;i<n;i++){
			if(i==0) sum+=num[i];
			else sum*=num[i];			
			if(sum>m){
				number=i;break;
			}
		}
		if(number!=-1) printf("%lld\n",number);
		else printf("%d\n",n);
	}
}
发布了22 篇原创文章 · 获赞 19 · 访问量 3546

猜你喜欢

转载自blog.csdn.net/KnightHONG/article/details/81358229