当前位置:网站首页>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;
}
边栏推荐
- A problem -- about dragging div in JS, when I change div to round, there will be a bug
- Touch hands to realize canal how to access Mysql to realize data write operation monitoring
- Introduction to MITK
- C language program: judging triangles
- List of security technologies to be considered in cloud computing
- QT qlineedit, qtextedit, qplaintextedit differences
- Namespace conflict problem
- What are the main threats to cloud security
- Rocky基础之修改网卡名为eth0
- Qt development tips
猜你喜欢

Chapter II linear table

Instant experience | further improve application device compatibility with cts-d

The second 1024, come on!

Introduction to MITK

Mlx90640 infrared thermal imager sensor module development notes (VIII)

SSRF vulnerability

Idea2020.1.4 packages package collapse

Creating, deleting and viewing Anaconda virtual environment

Solution to the problem of high collapse caused by float (including all methods)

Hard disk partition method
随机推荐
Solve blast database error: error pre fetching sequence data
iframe 标签
The second pre class exercise
The modified network card name of rocky foundation is eth0
C callback function, interface function pointer as function parameter, function pointer as structure member
5、 C language judgment statement
19、 ROS parameter name setting
Second class exercise
@DS('slave') 多数据源兼容事务问题解决方案
Robot mathematics foundation 3D space position representation space position
Mysql易错知识点整理(待更新)
8、 C scope rules
Establishment and traversal of binary tree (implemented in C language)
Shell command
MySQL authorization method
23、 TF coordinate transformation (III): dynamic coordinate transformation
4、 C language operators
Solution: attributeerror: type object 'h5py.h5a AttrID has no attribute __ reduce_ cython__
NCBI experience accumulation
Buuctf partial solution