2019.01.29【NOIP提高组】模拟B组 JZOJ 4244 yi

版权声明:虽然本蒟蒻很菜,但各位dalao转载请注明出处谢谢。 https://blog.csdn.net/xuxiayang/article/details/86689369

D e s c t i p t i o n Desctiption

m m 个人和 n n 艘飞船,每个飞船可以载 a i a_i 人飞行 b i b_i 点距离,现在要去距地球 k k 公里某星球来返,问至少需要几艘飞船


S o l u t i o n Solution

贪心水题。。。亦或是。。。排序水题?
很显然把小于 2 × k 2\times k 的都踢掉然后排序扫描一遍即可


C o d e Code

#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;int n,m,k,x,y,ans,a[100001],len;
inline char Getchar()
{
    static char buf[10000000],*p1=buf+10000000,*pend=buf+10000000;
    if(p1==pend)
    {
        p1=buf; pend=buf+fread(buf,1,10000000,stdin);
        if (pend==p1) return -1;
    }
    return *p1++;
}
inline long long read()
{
    char c;int d=1;long long f=0;
    while(c=Getchar(),!isdigit(c))if(c==45)d=-1;f=(f<<3)+(f<<1)+c-48;
    while(c=Getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
    return d*f;
}
inline bool cmp(int x,int y){return x>y;}
signed main()
{
	n=read();m=read();k=read();
	for(register int i=1;i<=n;i++){x=read();y=read();if(y>=2*k)a[++len]=x;}
	sort(a+1,a+1+len,cmp);
	for(register int i=1;i<=len;i++)
	{
		if(a[i]>=m) {m=0;ans++;break;}
		m-=a[i];ans++;
	}
	if(m==0)printf("%d",ans);
	else puts("-1");
}

猜你喜欢

转载自blog.csdn.net/xuxiayang/article/details/86689369
今日推荐