Codeforces 1256A 1257A
题目链接:https://codeforces.com/problemset/problem/1256/a
you have aa coins of value nn and bb coins of value 11. you always pay in exact change, so you want to know if there exist such xx and yy that if you take xx (0≤x≤a0≤x≤a) coins of value nn and yy (0≤y≤b0≤y≤b) coins of value 11, then the total value of taken coins will be ss.
you have to answer qq independent test cases.
the first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases. then qq test cases follow.
the only line of the test case contains four integers aa, bb, nn and ss (1≤a,b,n,s≤1091≤a,b,n,s≤109) — the number of coins of value nn, the number of coins of value 11, the value nn and the required total value.
for the ii-th test case print the answer on it — yes (without quotes) if there exist such xx and yy that if you take xx coins of value nn and yy coins of value 11, then the total value of taken coins will be ss, and no otherwise.
you may print every letter in any case you want (so, for example, the strings yes, yes, yes and yes will all be recognized as positive answer).
4 1 2 3 4 1 2 3 6 5 2 6 27 3 3 5 18
yes no no yes
思路:输入a,b,n,s,每个代表的意思为:a个含有价值n的硬币、b个含有价值1的硬币、价值为n的硬币、由这些硬币组成的目标数。先判断b个为1的硬币是否能直接达到s,能的话则直接输出,不能的话则进行下一步。
先判断价值为n的硬币最多能取多少个,即s对n取整,再将s减去s/n,再判断剩下的能不能由b个价值为1的硬币组成,能的话则满足,不能的话则不满足。
ac代码
#include<iostream> #include<cmath> using namespace std; int main() { int q; cin >> q; while(q--) { int a = 0,b = 0,sum = 0,n = 0,s = 0,temp = 0,min1 = 0; cin >> a >> b >> n >> s; if(b >= s) { cout << "yes" << endl; continue; } temp = s / n; min1 = min(a,temp); sum = s - min1 * n; if(b >= sum) { cout << "yes" << endl; continue; } else { cout << "no" << endl; continue; } } return 0; }
题目链接:https://codeforces.com/contest/1257/problem/a
上一篇: 孕妇为什么不能吃山楂这种食物呢
下一篇: 切西红柿不出汁的方法你到现在还不会吗
推荐阅读
-
『ACM C++』 Codeforces | 1066B - Heaters
-
『ACM C++』 Codeforces | 1003C - Intense Heat
-
Codeforces 939A题,B题(水题)
-
CodeForces 29D Ant on the Tree
-
Codeforces Global Round 9-C. Element Extermination
-
codeforces 712B Memory and Trident
-
CodeForces 962D Merge Equals
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
CodeForces 1326E - Bombs
-
CodeForces 612E Square Root of Permutation