题目链接:https://vjudge.net/contest/397104#problem/C
题解:两类饼,两类人,一类人只吃多的,一类人只吃少的,判断会不会有人不够吃
我们可以设两类饼为maxx,minn。当minn<只吃少的一类人数的时候,肯定不够吃。
剩下的情况只吃少的够吃,我们发现当两类饼的个数相同时,如果饼的个数小于人的个数,那么不行,反之,可以。
但这时候需要考虑能率能不能吃到一样多,即只吃多的那个人数是否大于等于maxx-minn,当满足这个条件就只需要判断maxx+minn与两类人数之和的关系。反之,就需要判断最小的人数和最小的个数的关系。
代码:
#include<iostream>
#include<algorithm>
typedef unsigned long long ull;
using namespace std;
int main()
{
ull n,m,v,c;
int t;
scanf("%d",&t);
while(t--)
{
ull sum=0;
scanf("%llu%llu%llu%llu",&v,&c,&n,&m);
ull maxn=max(v,c);
ull minn=min(v,c);
if(minn<m)//最小的饼数小于只吃最少的个数,此时肯定不够
{
cout<<"No"<<endl;
}
else if(maxn-minn>n)//不能够弥补那个差值
{
if(minn>=m)//够吃
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else if(maxn-minn<=n)//能够吃到一样多
{
if(minn+maxn<n+m)//不够吃
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
}
return 0;
}