当前位置: 移动技术网 > 移动技术>移动开发>Android > Codeforces C. A Cookie for You (模拟 / 分类 / 贪心) (Round #654 Div.2)

Codeforces C. A Cookie for You (模拟 / 分类 / 贪心) (Round #654 Div.2)

2020年07月18日  | 移动技术网移动技术  | 我要评论

传送门

题意: 主人住了两种饼干a,b块,现在邀请了两类客人n,m个。其中第一类客人喜欢吃多的饼干(相等的时候喜欢吃b),第二类客人喜欢吃少的饼干(相等的时候喜欢吃a)。
如果有客人吃不到自己想吃的饼干就好生气,但显然主人不希望客人生气。 所以现在让你来判断是否有可行方案让客人不生气。
在这里插入图片描述
思路:

  • 首先可判断饼干总数有没有客人总数多,再者因为二类客人喜欢吃少的,所以再判断min(a,b)是否有m多。
  • 先让m客人吃m个少类饼干,然后就只需要判断n客人是否生气了。
  • 再让n客人将多类的饼干吃得与少的一样,然后再交替吃饼干,最后判断是否有客人生气就好了。

代码实现:

#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int  inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll   mod = 1e9 + 7;
const int  N = 2e5 + 5;

int t, a, b, n, m;

signed main()
{
    IOS;
    
    cin >> t;
    while(t --){
        cin >> a >> b >> n >> m;
        if(a < b) swap(a, b);
        if(b < m || a + b < n + m){
            cout << "No" << endl;//如果所有饼干都没有客人多,或者二类客人不够吃
            continue; 
        }
        b -= m; // 先让m个二类客人先吃
        n -= (a - b);
        a = b; //再让一类客人将a饼干吃得和b饼干一样多
        if(n <= 0){
            cout << "Yes" << endl;
            continue; //如果一类客人够吃了
        }
        if(n > a + b) cout << "No" << endl; //明显一类病人把剩下的a,b饼干吃完都不够
        else cout << "Yes" << endl;
    }

    return 0;
}

本文地址:https://blog.csdn.net/Satur9/article/details/107386217

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网