浙江理工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 ...
随机推荐
- CentOs5.8下安装Oracle12C
12C安装向导: http://docs.oracle.com/database/121/LTDQI/toc.htm 12C下载地址: http://www.oracle.com/technetwor ...
- .NET 页面间传值的几种方法
1. QueryString 这是最简单的传值方式,但缺点是传的值会显示在浏览器的地址栏中且不能传递对象,只适用于传递简单的且安全性要求不高的数值. 传递: location.href="W ...
- Redis菜鸟汇总
1.是完全开源免费的,用C语言编写的,遵守BSD协议,是一个高性能的(key/value)分布式内存数据库,基于内存运行并支持持久化的NoSQL数据库,是当前最热门的NoSql数据库之一,也被人们称为 ...
- java中内部类使用小结
内部类是指在一个外部类中再定义一个类,类名不需要和文件名相同 内部类可以是静态的,类的修饰符可以是private,default,protect,public修饰 ,而外部类只能是public 和 d ...
- 建造者模式(Builder)
GOF:将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 类图:
- jdk安装配置具体分析
JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目录下,j ...
- Git 实战教程
CVS及SVN都是集中式的版本控制系统,而Git是分布式版本控制系统,集中式和分布式版本控制系统有什么区别呢? 先说集中式版本控制系统,版本库是集中存放在中央服务器的,而大家工作的时候,用的都是自己的 ...
- linux 查找命令
查找目录:find /(查找范围) -name '查找关键字' -type d查找文件:find /(查找范围) -name 查找关键字 -print
- 解决ssh登录后闲置时间过长而断开连接
++++++++++++++++++++++++++++ #!/usr/bin/env bash password_5="Uxxx7"host_5="129.x.x.1 ...
- maven说
maven打包命令:mvn assembly:assembly 打包成jar包需要修改配置把unpack改成false文件在: C:\Users\Administrator\.m2\repositor ...