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>
#