当前位置:网站首页>3511. 倒水问题
3511. 倒水问题
2022-07-28 14:15:00 【追寻远方的人】
有三个杯子,容量分别为 A,B,C。
初始时,C 杯装满了水,而 A,B 杯都是空的。
现在在保证不会有漏水的情况下进行若干次如下操作:
将一个杯子 x 中的水倒到另一个杯子 y 中,当 x 空了或者 y 满了时就停止(满足其中一个条件才停下)。
请问,在操作全部结束后,C 中的水量有多少种可能性。
输入格式
输入包含多组测试数据。
每组数据占一行,包含三个整数 A,B,C。
输出格式
每组数据输出一个结果,占一行。
数据范围
0≤A,B,C≤4000,
每个输入最多包含 100 组数据。
输入样例:
0 5 5
2 2 4
输出样例:
2
3
代码:
// 暴搜 枚举所有状态 判重
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL B = 10000;
int C[3];
unordered_set<LL> states;
unordered_set<int> cs;
LL get(int c[]) // 哈希
{
return c[2] * B * B + c[1] * B + c[0];
}
void pour(int c[], int i, int j)
{
int t = min(c[i], C[j] - c[j]);
c[i] -= t, c[j] += t;
}
void dfs(int c[])
{
states.insert(get(c));
cs.insert(c[2]);
int a[3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (i != j)
{
memcpy(a, c, sizeof a);
pour(a, i, j);
if (!states.count(get(a)))
dfs(a);
}
}
}
}
int main()
{
while (cin >> C[0] >> C[1] >> C[2])
{
states.clear();
cs.clear();
int c[3] = {
0, 0, C[2]};
dfs(c);
cout << cs.size() << endl;
}
return 0;
}
边栏推荐
- Third class exercise
- Wonderful frog -- how simple can it be to abandon the float and use the navigation bar set by the elastic box
- 6、 C language circular statement
- 安装mosek,license安装位置查找
- URP下使用GL进行绘制方法
- SystemVerilog
- Knowledge map Foundation (I) - what is knowledge map
- Use of beefs
- Reptile: from introduction to imprisonment (I) -- Concept
- Install scikit learn journey
猜你喜欢

MySQL authorization method

C language related programming exercises

Deploy flask on Alibaba cloud server
Node.js+express realizes the operation of MySQL database

企业微信客服链接,企业微信客服聊天

22、 TF coordinate transformation (II): static coordinate transformation

Bcompare key expired or bcompare license key revoked

VTK notes - picker picker summary

A problem -- about dragging div in JS, when I change div to round, there will be a bug

Talk about low code / zero code tools
随机推荐
Foundation of knowledge atlas (II) - knowledge expression system of knowledge atlas
C language related programming exercises
4、 C language operators
Partition and index of Oracle Database
Introduction to mqtt protocol
2021 year end summary of gains and losses
网络安全应急响应具体操作流程
C language exercises
SQL learning
Picture Trojan principle production prevention
CCSP international registered cloud security experts set up examination rooms in China
Buuctf partial solution
苹果iPhone手机APP应用图标隐藏怎么找回恢复显示在iPhone苹果手机桌面显示被隐藏的应用APP图标到iPhone苹果手机桌面?
QT qlineedit, qtextedit, qplaintextedit differences
Robot mathematics foundation 3D space position representation space position
23、 TF coordinate transformation (III): dynamic coordinate transformation
The first self introduction quotation
Shader顶点着色器修改顶点高度的一个思路
C language program: judging triangles
PHP memory horse