当前位置:网站首页>倒水问题(暑假每日一题 17)
倒水问题(暑假每日一题 17)
2022-08-08 00:15:00 【sweetheart7-7】
有三个杯子,容量分别为 A , B , C A,B,C A,B,C。
初始时, C C C 杯装满了水,而 A , B A,B A,B 杯都是空的。
现在在保证不会有漏水的情况下进行若干次如下操作:
将一个杯子 x x x 中的水倒到另一个杯子 y y y 中,当 x x x 空了或者 y y y 满了时就停止(满足其中一个条件才停下)。
请问,在操作全部结束后, C C C 中的水量有多少种可能性。
输入格式
输入包含多组测试数据。
每组数据占一行,包含三个整数 A , B , C A,B,C A,B,C。
输出格式
每组数据输出一个结果,占一行。
数据范围
0 ≤ A , B , C ≤ 4000 , 0≤A,B,C≤4000, 0≤A,B,C≤4000,
每个输入最多包含 100 100 100 组数据。
输入样例:
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;
}
边栏推荐
- Introduction to c language --- custom types: structures, enumerations, unions
- Flush it can open an account?Is it safe to open an account
- 【自然语言】------朴素贝叶斯对新闻进行预测分类
- Is the Flush stock trading software legitimate?is it safe?
- 喜讯|宏时数据获得CMMI3级认证!欢迎了解自研统一运维监控平台!
- Test the project management skills you should also have
- 程序后台运行并实时输出日志
- 永远不停歇
- 116. 在 SAPGUI 里使用 ABAP 报表上传 SAP UI5 应用到 ABAP 服务器
- Failed to initialize NVML: Driver/library version mismatch
猜你喜欢
随机推荐
MySQL笔记-05 数据表操作
有关原码,反码,补码那些事
Test the project management skills you should also have
D. Tournament Countdown(交互题)
在 SAPGUI 里使用 ABAP 报表上传 SAP UI5 应用到 ABAP 服务器试读版
C语言:求两个整数二进制位不同个数,基础方法+进阶方法
使用jmh框架进行benchmark测试
mysql select查询基本运算符练习题
像素画家KIN作品欣赏
继承关系下构造方法的访问特点
对PHP数组进行自定义排序
第三方应用接口回调错误
每周小结(*68):为什么要打架
2022-08-07:以下go语言代码输出什么?A:1 1;B:3 1;C:0 3;D:不能编译。 package main import ( “fmt“ “math“ ) func main
Analysis of Qiangwang Cup 2022 pwn competition questions - yakacmp
小程序API的Promise化
Flutter之图片选择器、支持多语言国际化、动画
MOSN 反向通道详解
多少建模师靠着zbrush这软件成家立业,你们还在等什么
炒股开户有佣金吗?开户安全吗







[email protected] 解决方法"/>
