当前位置:网站首页>3511. 倒水问题
3511. 倒水问题
2022-07-21 09:00:00 【Ray.C.L】
思路:暴力搜索每一种结果,我们在暴力时需要存储每次倒完水,3个水杯的状态,因为都小于4000,那么我们吧他们转化为1个三位的一万进制数来表示他的状态。注意倒水需要合法,i倒入j时,需要i有水,并且j杯子不会溢出。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>
using namespace std;
const int N = 10000;
typedef long long LL;
unordered_set<LL> status;
unordered_set<int> cs;
int C[3];
LL get(int c[]){
return c[2] * N * N + c[1] * N + c[0];
}
void pour(int a[], int i, int j){
int t = min(a[i], C[j] - a[j]);
a[i] -= t, a[j] += t;
}
void dfs(int c[]){
status.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(!status.count(get(a)))
dfs(a);
}
}
int main()
{
while(cin >> C[0] >> C[1] >> C[2]){
status.clear();
cs.clear();
int c[] = {
0, 0, C[2]};
dfs(c);
cout << cs.size() << endl;
}
return 0;
}
边栏推荐
- Preprocessing - outlier detection
- 庆功会代码
- Leetcode 48旋转图像(水平+主对角线)、Leetcode 221最大正方形(动态规划dp表示以ij为右下角的答案值)、Leetcode 240搜索二维矩阵II(排除行列法)
- 【御芯微WIoTa自组网协议开发套件试用体验】rt-thread bsp软件包制作
- 单调栈与单调队列(线性复杂度优化)
- 1. Source code analysis of Nacos configuration center Hello World
- Pytorch common code snippet collection
- m在ISE平台下使用verilog开发基于FPGA的GMSK调制器
- 二维费用的背包问题(01背包)
- Knapsack problem of two-dimensional cost (01 knapsack)
猜你喜欢
午休专列&问题思考:关于多维数组统计各元素的数量
慧荣科技与江波龙协同提升手机存储竞争力
Unity_ Demo | medieval 3d-rpg game
动态递归之严格位置依赖优化
m在simulink进行DS-CDMA建模,然后通过MATLAB调用simulink模型进行误码率仿真
LeetCode 300最长递增子序列(贪心 + 二分查找比nums[i]小的第一个元素下标)、LeetCode 200岛屿数量(深搜)、LeetCode 494目标和(dfs回溯)
Pytorch common code snippet collection
Modbus通信协议规范(中文)分享
「华流才是顶流」?分享你心目中的YYDS
PyTorch常用代码段合集
随机推荐
PyTorch常用代码段合集
When Lenovo Xiaoxin Air13 Pro reinstalls win10, the storage device driver cannot be found
VALDO2021——血管病变检测挑战赛之血管间隙分割(一)
MySQL之binlog用法及介绍
3. Project structure of source code analysis of Nacos configuration center
請問這是錶示mysql的binlog已經開啟嗎?
ssh方式登录huawei设备
m基于中继协助的认知无线电频谱切换机制的matlab仿真分析
一文深入浅出理解国产开源木兰许可系列协议
动态递归之严格位置依赖优化
m在ISE平台下使用verilog开发基于FPGA的GMSK调制器
Riding the wind and waves, the road of digital transformation in the era of financial technology
Major breakthrough! Successful development of the first domestic scientific computing software
OSPF knowledge summary
2022.7.20-----leetcode. one thousand two hundred and sixty
如何使用订单流分析工具(上)
Easyexcel realizes file upload - batch insert file download
Oracle中對空字符串的判斷
浏览器本地存储webStroage
利用正则回溯最大次数上限进行绕过