CSU 1209 Three Jugs (数论)
2013-10-04 20:17
246 查看
1209: Three Jugs
Time Limit: 1 Sec Memory Limit:128 MB
Submit: 304 Solved: 57
[Submit][Status][Web
Board]
Description
We have three jugs A, B, C without any calibration, and an infinite supply of water. There are three types of actions that you can use:(1) Fill a jug.
(2) Empty a jug.
(3) Pour from one jug to another.
Pouring from one jug to another stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons, B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A.
Now you need to calculate the minimum accurate gallons of water we can get by using the three jugs.
Input
There is an integer T (1 <= T <= 200) in the first line, means there are T test cases in total.For each test case, there are three integers a, b, c (1 <= a, b, c <= 10^18) in a line, indicate the capacity (unit: gallon) of the three jugs.
Output
For each test case, you should print one integer in a line, indicates the minimum accurate gallons of water we can get by using the three jugs.Sample Input
23 6 9
6 10 15
Sample Output
31
HINT
Source
CSU Monthly 2013 Apr.题意:
有三个瓶子,可以往里面倒水,也可以三个之间互相倒水,但当一只瓶里水满或另一瓶子水空时停止。
问经过任意步骤后,可从某一瓶子里倒出来的最少的水量。
例如第2个例子:
1) 1瓶子和2瓶子先装满水
2) 1瓶子往3瓶子里倒完水,1瓶子空,3瓶子里6加仑水
3)2瓶子往3瓶子里倒9加仑水,3瓶子满,2瓶子剩1加仑水
4)可从2瓶子里倒出1加仑水
思路:
对三个数求GCD
/************************************************************************* > File Name: I.cpp > Author: BSlin > Mail: > Created Time: 2013年10月03日 星期四 17时56分26秒 ************************************************************************/ #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <algorithm> #include <iterator> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #define MP make_pair #define INF (1<<30) #define PI acos(-1.0) #define esp 1e-8 const int dx[4]={0,0,0,0}; using namespace std; #define read freopen("in.txt","r",stdin) #define write freopen("out.txt","w",stdout) #if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__) #define LL __int64 #define LLS "%" "I" "6" "4" "d" #else #define LL long long #define LLS "%" "l" "l" "d" #endif LL gcd(LL a, LL b) { if(b == 0) return a; return gcd(b,a%b); } int main(int argc, char** argv) { int t; LL a,b,c; scanf("%d",&t); while(t--) { scanf(LLS LLS LLS,&a,&b,&c); printf(LLS"\n",gcd(gcd(a,b),c)); } return 0; }
相关文章推荐
- CSU1209-Three Jugs-GCD
- CSU 1209 Three Jugs
- CSU - 1209 Three Jugs
- CSU1162-Balls in the Boxes-快速幂、数论
- CSU 1803:2016(数论)
- CSU 1803 2016(数论)
- csu 1320 Scoop water (数论)
- csu 1392 Number Trick (数论)
- csu 1756 prime(数论)
- 1209: Three Jugs
- CSU 1803 2016 (数论+思路)
- 2017年暑假组队训练赛-No.7 K - 简单的数论 CSU - 1871
- csu 1416 Practical Number(数论,结论题)
- COJ 1209: Three Jugs
- csu 1756(数论+去重)
- CSU 1871 中南大学网络赛E题 简单的数论
- CSU - 1803 数论GCD
- hdoj 1286 找新朋友 【数论之欧拉函数】
- Bi-shoe and Phi-shoe (数论(欧拉函数))
- fzu1759:数论高次幂降幂