题目链接无脑博士的试管们

思路:直接模拟倒水过程即可,但是需要记忆判断当前的情况是否已经处理过。dfs和bfs都ok

AC代码

#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 20 + 5;
int dp[maxn][maxn];
set<int>ans;
int v[3];
void dfs(int a, int b, int c) {
	//printf("%d %d %d\n", a, b, c);
	if(dp[a][b]) return;
	dp[a][b] = 1;
	if(a == 0) ans.insert(c);
	//倒水
	for(int i = 0; i < 3; ++i) {
		for(int j = 0; j < 3; ++j) {
			if(i == j) continue;
			int u[3] = {a, b, c};
			int pour = min(u[i], v[j]-u[j]);
			if(pour == 0) continue;
			u[i] -= pour;
			u[j] += pour;
			dfs(u[0], u[1], u[2]);
		}
	}
}

int main() {
	while(scanf("%d%d%d", &v[0], &v[1], &v[2]) == 3) {
		ans.clear();
		memset(dp, 0, sizeof(dp));
		dfs(0, 0, v[2]);
		for(set<int>::iterator it = ans.begin(); it != ans.end(); ++it) {
			if(it == ans.begin()) printf("%d", *it);
			else printf(" %d", *it);
		}
		printf("\n");
	}
	return 0;
}

如有不当之处欢迎指出!

计蒜客 无脑博士 bfs的更多相关文章

  1. 计蒜客 无脑博士的试管们 【dfs】

    题目链接:https://nanti.jisuanke.com/t/31 题目大意: 无脑博士有三个容量分别是A,B,C 升的试管,A,B,C 分别是三个从 1 到20 的整数,最初,A 和 B 试管 ...

  2. [计蒜客] 矿石采集【记搜、Tarjan缩点+期望Dp】

    Online Judge:计蒜客信息学3月提高组模拟赛 Label:记搜,TarJan缩点,树状数组,期望Dp 题解 整个题目由毫无关联的两个问题组合成: part1 问题:对于每个询问的起点终点,求 ...

  3. 计蒜客 作弊揭发者(string的应用)

    鉴于我市拥堵的交通状况,市政交管部门经过听证决定在道路两侧安置自动停车收费系统.当车辆驶入车位,系统会通过配有的摄像头拍摄车辆画面,通过识别车牌上的数字.字母序列识别车牌,通过连接车管所车辆信息数据库 ...

  4. 计蒜客的一道题dfs

    这是我无聊时在计蒜客发现的一道题. 题意: 蒜头君有一天闲来无事和小萌一起玩游戏,游戏的内容是这样的:他们不知道从哪里找到了N根不同长度的木棍, 看谁能猜出这些木棍一共能拼出多少个不同的不等边三角形. ...

  5. 计蒜客模拟赛5 D2T1 成绩统计

    又到了一年一度的新生入学季了,清华和北大的计算机系同学都参加了同一场开学考试(因为两校兄弟情谊深厚嘛,来一场联考还是很正常的). 不幸的是,正当老师要统计大家的成绩时,世界上的所有计算机全部瘫痪了. ...

  6. 计蒜客 等边三角形 dfs

    题目: https://www.jisuanke.com/course/2291/182238 思路: 1.dfs(int a,int b,int c,int index)//a,b,c三条边的边长, ...

  7. 计蒜客 方程的解数 dfs

    题目: https://www.jisuanke.com/course/2291/182237 思路: 来自:https://blog.csdn.net/qq_29980371/article/det ...

  8. 计蒜客 买书 dfs

    题目: https://www.jisuanke.com/course/2291/182236 思路: 递归解决,从第一本书开始,每本书都有两种选择: //index是book里面每本书价格的下标, ...

  9. 计蒜客:Entertainment Box

    Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...

随机推荐

  1. scrapy_移除内容中html标签

    如何移除所获取内容中多余的html标签? 通过w3lib模块和re模块 #!/usr/bin/python3 # -*- coding: UTF-8 -*- __author__ = 'beimenc ...

  2. linkin大话设计模式--建造模式

    linkin大话设计模式--建造模式 建造模式是对象的创建模式,可以讲一个产品的内部表象与产品的生成过程分割开来,从而可以使一个建造过程生成具有不同的内部表象的产品对象. 建造模式的结构: 抽象建造者 ...

  3. 远程服务调用(RMI)

    模块概念的引入,是本框架的一大优势,而跨JVM的远程服务调用则是另一个最有价值的功能. <本地服务调用>一文中我们讲解了跨模块间的服务调用可以是这样的: ServiceHelper.inv ...

  4. android dialog弹出的情况下监听返回键

    view = LayoutInflater.from(getActivity()).inflate( R.layout.dialog_tips, null); title2 = (TextView) ...

  5. 02_HTML5+CSS详解第二天

    html5大纲分析工具:https://gsnedders.html5.org/outliner/ <section> <h1>HTML部分</h1> <se ...

  6. 关于awk的多文件处理

    关于awk的多文件处理: awk的数据输入有两个来源,标准输入和文件,后一种方式支持多个文件,如1.shell的Pathname Expansion方式:awk '{...}' *.txt # *.t ...

  7. tomcat调优(三)

    标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 1.安全优化 降权启动 telnet管理端口保护 ajp连接端口保护 禁用管理端 关闭本地默认 ...

  8. 集中式(SVN)和分布式(Git)版本控制系统的简单比较

       集中式(SVN)  分布式(Git)  是否有中央服务器  有.开发人员需要从中央服务器获得最新版本的项目然后在本地开发,开发完推送给中央服务器.因此脱离服务器开发者是几乎无法工作的  没有中央 ...

  9. Codeforce D. Make a Permutation!

    D. Make a Permutation! time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  10. ABP官方文档翻译 6.1.3 异常处理

    处理异常 介绍 启用错误处理 Non-Ajax请求 显示异常 UserFriendlyException Error模型 AJAX请求 异常事件 介绍 此文档是与ASP.NET MVC和Web API ...