Educational Codeforces Round 108 (Rated for Div. 2)题解

题目链接

A.Red and Blue Beans

题目描述
给定红色豆子 r 个,蓝色豆子 b 个,问是否存在一种分装方法,使得每个袋子里两种颜色的豆子至少都有一个,且两种豆子的数量差不超过 d 。
解题思路
关键点在于如何使差值尽可能小。贪心的减小一个袋子里,两种豆子的数目,那么设 r > b,就分为 b 份,再将 r 平均分到这些袋子里。比较差值与 d 的大小关系即可。

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;
int main(){
   
    int t;
    cin>>t;
    while(t--){
   
        int r, b, d;
        cin >> r >> b >> d;
        int num = min(r, b);
        int num1 = max(r, b);
        int tag = num1 / num;
        int tag1 = num1 % num;
        if(tag1){
   
            tag++;
        }
        if(tag - 1 > d){
   
            cout << "NO" << endl;
        }
        else{
   
            cout << "YES" << endl;
        }
    }
        return 0;
}
B.The Cake Is a Lie

题目大意
给定一个 n*m 的矩阵,要求从(1,1)移动到(n,m),每走一步需要花费一定的值,若沿着 y 的正向走一步,花费 x,沿着 x 的正向走一步,花费 y (规定只能沿着x正向和y正向两个方向走),问是否可以在花费恰好等于 k 的情况下走完全程?
解题思路
经过推导可发现无论怎么走,花费都是不变的,推导过程见下图:
证明过程
所以仅需判断nm - 1 与 k 是否相等

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值