USACO training course Mother's Milk /// DFS(有点意思) oj10120
题目大意:
输入 A B C 为三个容器的容量
一开始A B是空的 C是满的
每一次倾倒只能在 盛的容器满 或 倒的容器空 时才停止
输出当A容器空时 C容器内剩余量的所有可能值
8 9 10
2 5 10
1 2 8 9 10
5 6 7 8 9 10
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<math.h>
using namespace std;
int flag[],vis[][],ans[];
int a,b,c,len;
void DFS(int nowa,int nowc)
{
if(vis[nowa][nowc]) return;
vis[nowa][nowc]=; if(nowa==&&!flag[nowc])
flag[nowc]=, ans[len++]=nowc; int nowb=c-nowa-nowc; if(nowa&&nowc<c) ///a->c
DFS(nowa-min(nowa,c-nowc),nowc+min(nowa,c-nowc));
if(nowa&&nowb<b) ///a->b
DFS(nowa-min(nowa,b-nowb),nowc);
if(nowc&&nowa<a) ///c->a
DFS(nowa+min(nowc,a-nowa),nowc-min(nowc,a-nowa));
if(nowc&&nowb<b) ///c->b
DFS(nowa,nowc-min(nowc,b-nowb));
if(nowb&&nowa<a) ///b->a
DFS(nowa+min(a-nowa,nowb),nowc);
if(nowb&&nowc<c) ///b->c
DFS(nowa,nowc+min(c-nowc,nowb));
}
int main()
{
while(~scanf("%d%d%d",&a,&b,&c))
{
memset(ans,,sizeof(ans));
memset(vis,,sizeof(vis));
memset(flag,,sizeof(flag));
len=;
DFS(,c);
sort(ans,ans+len);
for(int i=;i<len-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[len-]);
} return ;
}
USACO training course Mother's Milk /// DFS(有点意思) oj10120的更多相关文章
- USACO 1.4 Mother's Milk
Mother's Milk Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numb ...
- USACO Section1.4 Mother's Milk 解题报告
milk3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
- 洛谷P1215 [USACO1.4]母亲的牛奶 Mother's Milk
P1215 [USACO1.4]母亲的牛奶 Mother's Milk 217通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
- P1215 [USACO1.4]母亲的牛奶 Mother's Milk
P1215 [USACO1.4]母亲的牛奶 Mother's Milk 题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满 ...
- luogu P1215 [USACO1.4]母亲的牛奶 Mother's Milk
题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到另一个桶中,直到被灌桶装满或原桶空了 ...
- 洛谷 P1215 [USACO1.4]母亲的牛奶 Mother's Milk
题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到另一个桶中,直到被灌桶装满或原桶空了 ...
- USACO Training刷题记录 By cellur925
Section 1.1 Your Ride Is Here 貌似没啥可说 Greedy Gift Givers 上来就想stl map映射,有两个坑:如果送给别人的人数为0,那么需要特判一下,防止整数 ...
- 关于USACO Training
做了这么久的题目,突然发现最经典的 USACO Training 还没有做过?加速水一遍吧!我会把题解放在上面的.
随机推荐
- NX二次开发-UFUN批量操作图层状态UF_LAYER_set_many_layers_status
NX11+VS2013 #include <uf.h> #include <uf_ui.h> #include <uf_layer.h> UF_initialize ...
- 笨办法学Python记录--习题12-14 主要是pydoc用法,raw_input,argv
20140413 -- 习题12 - 14 1. pydoc在windows的用法,必须进入到python安装目录,执行Python -m pydoc raw_input; 网上给出了一个好玩的,不过 ...
- Fedora Linux 安装Qt5.2.0
1.下载 qt-linux-opensource-5.2.0-x86-offline.run 2. chmod u+x ./qt-linux-opensource-5.2.0-x86-offline. ...
- ionic:安装
ylbtech-ionic:安装 1.返回顶部 1. ionic 安装 本站实例采用了ionic v1.3.2 版本,使用的 CDN 库地址: <link href="https:// ...
- Python中的startswith和endswith函数使用实例
Python中的startswith和endswith函数使用实例 在Python中有两个函数分别是startswith()函数与endswith()函数,功能都十分相似,startswith()函数 ...
- DXP 快捷键
EC 复制 EY array paste TU: update
- jpa简单规则(转https://www.cnblogs.com/rulian/p/6434631.html)
一.常用规则速查 1 And 并且2 Or 或3 Is,Equals 等于4 Between 两者之间5 LessThan 小于6 LessThanEqual 小于等于7 Gre ...
- mysql 需要掌握的重点
1. 安装mysql: google it.2. 新建database,table: create database database_name;create table table_name ...
- jsonArray转换成List
从字符串String转换成List 字符串格式: String jsonstr = "{'studentsjson':[{'student':'张三'},{'student':'李四'}] ...
- CSV导入到hive中,处理分号问题
1.导入的原数据 103744;545479945;2017.05.17 06:41:08;sell;eurusd_;0.10;1.11080;1.11280;1.10880;1.11081;0.00 ...