当前位置:网站首页>3511. Water pouring problem
3511. Water pouring problem
2022-07-28 15:13:00 【Pursue people far away】
There are three cups , The capacities are A,B,C.
At the beginning ,C The cup is full of water , and A,B The cups are empty .
Now, under the condition that there is no water leakage, carry out the following operations several times :
Put a cup x Pour the water in another cup y in , When x Empty or y Stop when it's full ( Meet one of the conditions before stopping ).
Excuse me, , After all operations are completed ,C How many possibilities are there for the amount of water in .
Input format
Input contains multiple sets of test data .
Each group of data occupies one row , Contains three integers A,B,C.
Output format
Each group of data outputs a result , Occupy a line .
Data range
0≤A,B,C≤4000,
Each input contains at most 100 Group data .
sample input :
0 5 5
2 2 4
sample output :
2
3
Code :
// Violent search Enumerate all States Weight determination
#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[]) // Hash
{
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;
}
边栏推荐
- Compilation language and interpretation language
- 16、 Launch file label of ROS (II)
- Shader顶点着色器修改顶点高度的一个思路
- List of security technologies to be considered in cloud computing
- The difference between @notnull, @notblank, @notempty of commonly used verification annotations
- CCSP国际注册云安全专家在中国设置考场
- SSRF vulnerability
- CCSP 云安全设计原则都有哪些
- 云计算需要考虑的安全技术列举
- 17、 Solutions to duplicate names of ROS function packages and nodes
猜你喜欢

celery 相关

Foundation of knowledge atlas (II) - knowledge expression system of knowledge atlas

21、 TF coordinate transformation (I): coordinate MSG message
![UTF-8、UTF-16 和 UTF-32 字符编码之间的区别?[图文详解]](/img/a9/336390db64d871fa1655800c1e0efc.png)
UTF-8、UTF-16 和 UTF-32 字符编码之间的区别?[图文详解]

buuctf_ php

经典Dijkstra与最长路

PS how to crop photos

SQL labs detailed problem solving process (less1-less10)

Compose learning notes 1-compose, state, flow, remember

Instructions for common symbols in kotlin
随机推荐
VTK notes - picker picker summary
Repvgg paper explanation and model reproduction using pytoch
PHP magic method
What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]
Application of edge technology and applet container in smart home
7、 Detailed explanation of C language function definition
Examples of Pareto optimality and Nash equilibrium
NCBI experience accumulation
软件开发三大痛点!小程序容器如何解决?
Some considerations for installing Oracle11g
2021-09-02
Chapter II linear table
@Solution to DS ('slave') multi data source compatible transaction problem
Compose learning notes 2 - launchedeffect, status and status management
Chapter I Introduction
SQL learning
Knowledge map Foundation (I) - what is knowledge map
Chapter 3 stack, queue and array
6、 C language circular statement
Basic operation implementation of sequence table