当前位置:网站首页>Acwing daily question three thousand five hundred and eleven
Acwing daily question three thousand five hundred and eleven
2022-07-19 06:10:00 【Nickname: Wang Nengquan】
ACWing A daily topic .3511
subject :
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
Answer key :
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>
using namespace std;
typedef long long LL;
const LL B = 10000; // Max. per bucket 4000, So use a LL Type number to store the status of three buckets
int C[3];
unordered_set<LL> states; // The state of three barrels
unordered_set<int> cs; // bucket C The state of
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;
}
/* Deep search : Input : The volume of water already filled in three buckets Array function : 1. Add the state of three buckets states; 2. take C The capacity of water in the bucket at this time is added cs; 3. Pour water between the three buckets , If it doesn't appear states Internal state , Proceed to the state at this time fds; */
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); // i Bucket to j Pour water in the bucket
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]}; // The capacity of water in three barrels
dfs(c);
cout << cs.size() << endl;
}
return 0;
}
边栏推荐
- Hra2460d-2w high voltage power supply high voltage module - high voltage - high precision hra2460d-2w
- 2022 robocom world robot developer competition - undergraduate group (provincial competition)
- 2021-11-26 pyautogui cooperates with lightning simulator to realize the automation of mobile app check-in and answer questions
- 带透明png转换成c数组
- 2021 - 09 - 15
- Acwing game 58 (AK)
- 计算几何(4.17)
- Tips for using tp4054 charging IC -- used in conjunction with Zhongke Lanxun ab5365b
- 自动补全 & (自定义)拼音分词器 & 搜索时注意事项
- 【力扣】另一棵树的子树
猜你喜欢

2022/07/11 第五小组 丁帅 学习笔记 day04
![Vscode instant English translation plug-in [translation (English Chinese Dictionary)]](/img/f4/9bd90910fef061b423ea8309fab439.png)
Vscode instant English translation plug-in [translation (English Chinese Dictionary)]

【力扣】设计循环队列

2021-09-15

DSL实现Metrics 聚合

3.7V lithium battery boost to 5v1a, fs2114 boost conversion chip design layout

2022/07/10 第五小组 丁帅 学习笔记 day03

【力扣】用队列实现栈

Hm9922 switching buck LED constant current driver IC

Basic mathematics course 2_ Euler function, linear sieve, extended Euler
随机推荐
【力扣】相同的树
获取当前年月日、时分秒、星期,并实时更新
Speed sensor signal isolation, acquisition and transformation, sine wave and sawtooth wave signal input, square wave signal output, signal converter
Peerless good problem (bit operation optimization DP)
數學基礎課2_歐拉函數,線性篩,擴歐
4-channel encoder pulse counter, 8-Channel do, Modbus TCP module
c语言调用文件浏览器,实现选择文件的效果
DSL实现Metrics 聚合
Unity2d learning Fox game production process 1: basic game character control, animation effects, lens control, item collection, bug optimization
Fs4061a (5V USB input, double lithium battery series application, 5V boost charging, 8.4v Management IC
Simple chrome script automatically skips the charging acknowledgment page after the video playback of station B ends
Fs68001 wireless charging SOC chip has simple periphery and schematic diagram of 5W wireless charging scheme
2022/07/11 第五小组 丁帅 学习笔记 day04
Wireless charging chip IC
Cours de mathématiques de base 2 Fonction Euler, écran linéaire, élargissement de l'Europe
busybox date 日期增加一天明天 网上都是减一天 昨天
Wireless charging mouse pad RGB LED lighting wireless charging mouse pad
Tips for using tp4054 charging IC -- used in conjunction with Zhongke Lanxun ab5365b
Baby Ehab partitions again (DP, construction, bit operation)
5-17陕西科技大学的隐藏学生服务