有三个杯子,容量分别为 。
初始时, 杯装满了水,而
现在在保证不会有漏水的情况下进行若干次如下操作:
将一个杯子 中的水倒到另一个杯子
中,当
空了或者
请问,在操作全部结束后,
输入格式
输入包含多组测试数据。
每组数据占一行,包含三个整数 。
输出格式
每组数据输出一个结果,占一行。
数据范围
每个输入最多包含
输入样例:
0 5 5
2 2 4
输出样例:
2
3
#include<iostream>
#include<unordered_set>
using namespace std;
int A, B, C;
void dfs(int a, int b, int c, unordered_set<int> &S){
if(a == A && b == B || c == 0){
S.insert(c);
return;
}
int x;
if(A && a != A) {
x = min(A - a, c);
dfs(a + x, b, c - x, S);
}
if(B && b != B){
x = min(B - b, c);
dfs(a, b + x, c - x, S);
}
if(A && a == A){
x = min(a, B - b);
dfs(a - x, b + x, c, S);
}
if(B && b == B){
x = min(A - a, b);
dfs(a + x, b - x, c, S);
}
}
int main(){
while(cin >> A >> B >> C){
unordered_set<int> S;
dfs(0, 0, C, S);
cout << S.size() << endl;
}
return 0;
}