Jug Hard
来源:互联网 发布:手机淘宝店铺怎么激活 编辑:程序博客网 时间:2024/06/06 01:45
Description
You have two empty jugs and tap that may be used to fill a jug. When filling a jug from the tap, you can only fill it completely (i.e., you cannot partially fill it to a desired level, since there are no volume measurements on the jug).
You may empty either jug at any point.
You may transfer water between the jugs: if transferring water from a larger jug to a smaller jug, the smaller jug will be full and there will be water left behind in the larger jug.
Given the volumes of the two jugs, is it possible to have one jug with some specific volume of water?
Input
The first line contains T, the number of test cases (1 ≤ T 100 000). Each test case is composed of three integers: a b d where a and b (1 ≤ a, b ≤ 10 000 000) are the volumes of the two jugs, and d is the desired volume of water to be generated. You can assume that d ≤ max(a,b).
Output
For each of the T test cases, output either Yes or No, depending on whether the specific volume of water can be placed in one of the two jugs.
Sample Input
3
8 1 5
4 4 3
5 3 4
Sample Output
Yes
No
Yes
题意:给你两个空的罐子,问你是否可以用这两个罐子获得一定体积的水,这两个罐子上都没有确定的刻度,若要用罐子接水则必须要接满。
思路:若这两个罐子的体积最大公约数是要获得的水的体积的因子则可以;否则不行。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int gcd(int a,int b){ return b==0?a:gcd(b,a%b);}int main(){ int t; scanf("%d",&t); while(t--) { int a,b,c; scanf("%d %d %d",&a,&b,&c); if(c%gcd(a,b)==0) printf("Yes\n"); else printf("No\n"); } return 0;}
- Jug Hard
- Jug Hard【ZSTUOJ--4216】
- Problem D: Jug Hard
- 浙江理工2015.12校赛-G Jug Hard
- 2015浙江理工校赛G Jug Hard (数论orBFS)
- 湖南中医药大学2017年集训队第四场选拔赛-Problem D: Jug Hard
- 【ZSTU4216 2015年12月浙理工校赛 G】【数论 gcd】Jug Hard 两个杯子倒水能否倒腾到目标值
- hard
- Water and Jug Problem
- Water and Jug Problem
- Water and Jug Problem
- Water and Jug Problem
- Jug 倒水问题 ZJU ACM
- 365. Water and Jug Problem
- 【Leetcode】Water and Jug Problem
- leetcode:Water and Jug Problem
- leetcode365. Water and Jug Problem
- 365. Water and Jug Problem
- map中存放的value是引用变量
- Python: 你不知道的 super
- JDBC中使用Java8的日期LocalDate、LocalDateTime
- Android 属性动画 实现view翻转 旋转 平移 拉伸 透明度 背景颜色变换
- 构建微服务:Spring boot 入门篇
- Jug Hard
- Qt designer 添加菜单动作
- python下的随机函数总结
- SPIFFS技术手册
- 581. Shortest Unsorted Continuous Subarray
- Eclipse FindBugs插件安装与使用
- USB Class Codes
- mybatis中使用Java8的日期LocalDate、LocalDateTime
- CC2640R2 BLE5 Long Range mode