浙江理工2015.12校赛-G Jug Hard
Jug Hard
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 1172 Solved: 180
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
an+bn=d;
证明等式的成立,就是扩展欧几里得的证明
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int GCD(int a,int b)
{
return b==0?a:GCD(b,a%b);
}
int main()
{
int T;
int n ,m,d;
scanf("%d",&T);
while(T--)
{
scanf("%d %d %d",&n,&m,&d);
printf("%s\n",d%GCD(n,m)==0?"Yes":"No");
}
return 0;
}
浙江理工2015.12校赛-G Jug Hard的更多相关文章
- 浙江理工2015.12校赛-A
孙壕请一盘青岛大虾呗 Time Limit: 5 Sec Memory Limit: 128 MB Submit: 577 Solved: 244 Description 话说那一年zstu与gdut ...
- 浙江理工2015.12校赛-F Landlocked
Landlocked Time Limit: 5 Sec Memory Limit: 128 MB Submit: 288 Solved: 39 Description Canada is not a ...
- 浙江理工2015.12校赛-B 七龙珠
七龙珠 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 781 Solved: 329 Description 话说孙壕请吃了青岛大虾后,一下子变穷了,就 ...
- 2015 GDUT校赛
周末打了个GDUT的校赛,也是作为SCAU的一场个人排位. 比赛中竟然卡了个特判,1个半钟就切了5条了,然后一直卡. 还有其他两条可以做的题也没法做了,性格太执着对ACM来说也是错呀. 讲回正题 . ...
- 2017年浙江理工大学程序设计竞赛校赛 题解&源码(A.水, D. 简单贪心 ,E.数论,I 暴力)
Problem A: 回文 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1719 Solved: 528 Description 小王想知道一个字 ...
- 2015 多校赛 第七场 1011 (hdu 5379)
题意:给定一棵树,树上有 n 个节点.问有多少种方案,使得在每个节点上依次放置数 1~n 后,每个节点的儿子节点上的数连续(比如 1 为根,有1-2,1-3,1-4,则令2,3,4上的数连续),每个子 ...
- 2015 多校赛 第五场 1010 (hdu 5352)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5352 看题看得心好累. 题目大意: 给出 n 个点,依次执行 m 次操作:输入“1 x”时,表示将与 ...
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- 2018年浙江理工大学程序设计竞赛校赛 Problem I: 沙僧
沙僧 思路: dfs序+差分数组 分层考虑,通过dfs序来查找修改的区间段,然后用差分数组修改 代码: #include<bits/stdc++.h> using namespace st ...
随机推荐
- C# @符号的作用, 可定义关键字为变量名
一 字符串中的用法字符@表示,其后的字符串是个“逐字字符串”(verbatim string).@只能对字符串常量作用.1.用于文件路径以下是引用片段:string s_FilePath =" ...
- Hibernate的一级二级缓存机制配置与测试
特别感谢http://www.cnblogs.com/xiaoluo501395377/p/3377604.html 在本篇随笔里将会分析一下hibernate的缓存机制,包括一级缓存(session ...
- WooCommerce代码收集
修改首页和分类页面每页产品数量 每页显示多少产品默认跟随设置 » 阅读设置 » 博客页面至多显示的值,若要产品索引页和博文索引页使用不同的设置,可以使用下面的代码为产品索引页单独设置每页产品数. ad ...
- JavaScript入门篇 第一天
使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<script>< ...
- where过滤字句
无条件为真 为假 别名不能直接用来当做查询来用 只能如此 下面这些语句是可以使用的,使用的是排序规则
- Cookie 知识点再整理
1. Cookie 是存储在客户端 内存 或者 硬盘(例如火狐把 Cookie 存储在 C:\Documents and Settings\用户名\Application Data\Mozilla\ ...
- Different Approaches for MVCC
https://www.enterprisedb.com/well-known-databases-use-different-approaches-mvcc Well-known Databases ...
- Java中的virtual method
今天看jcvm的标准的 时候,看到有一个virtual method,感觉很疑惑,以前看Java的时候并没有发现有这类方法. 百度.Google了一下,才发现,Java中普通方法就是virtual m ...
- 四个使用promise的语句之间的不同点在哪儿?
http://jsbin.com/tuqukakawo/1/edit?js,console,output #1 doSomething().then(function () { return doSo ...
- golang protobuf SetExtension
对golang protobuf 的扩展字段赋值时候一直提示proto: bad extension value type clkUrl:="z.cn" proto.SetExte ...