Mother's Milk

Farmer John has three milking buckets of capacity A, B, and C liters. Each of the numbers A, B, and C is an integer from 1 through 20, inclusive. Initially, buckets A and B are empty while bucket C is full of milk. Sometimes, FJ pours milk from one bucket to another until the second bucket is filled or the first bucket is empty. Once begun, a pour must be completed, of course. Being thrifty, no milk may be tossed out.

Write a program to help FJ determine what amounts of milk he can leave in bucket C when he begins with three buckets as above, pours milk among the buckets for a while, and then notes that bucket A is empty.

PROGRAM NAME: milk3

INPUT FORMAT

A single line with the three integers A, B, and C.

SAMPLE INPUT (file milk3.in)

8 9 10

OUTPUT FORMAT

A single line with a sorted list of all the possible amounts of milk that can be in bucket C when bucket A is empty.

SAMPLE OUTPUT (file milk3.out)

1 2 8 9 10

SAMPLE INPUT (file milk3.in)

2 5 10

SAMPLE OUTPUT (file milk3.out)

5 6 7 8 9 10

题目大意:倒牛奶。。。。你有三个筒子ABC会告诉你容积,开始的时候AB都是空的,C是满的,问你在不把牛奶倒出三个筒子之外的情况下,在A桶是空的情况下,C桶有多少奶,顺序输出所有可能性。
思路:没什么说的了,BFS。代码写在下面
 /*
ID:fffgrdcc1
PROB:milk3
LANG:C++
*/
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
bool bo[][][]={};
struct str
{
int a,b,c;
}e[];
int cnt=;
int q[],tail,head;
int a,b,c,A,B,C;
int main()
{
freopen("milk3.in","r",stdin);
freopen("milk3.out","w",stdout);
scanf("%d%d%d",&A,&B,&C);
head=-;tail=;e[].a=e[].b=;e[].c=C;q[]=;bo[][][C]=;
while(head<tail)
{
head++;
int temp;
a=e[head].a,b=e[head].b,c=e[head].c;
temp=min(a,C-c);//a2c
a-=temp;c+=temp;
if(!bo[a][b][c])
{
bo[a][b][c]=;
q[++tail]=cnt;
e[++cnt].a=a;
e[cnt].b=b;
e[cnt].c=c;
}
a+=temp;c-=temp; temp=min(A-a,c);//c2a
a+=temp;c-=temp;
if(!bo[a][b][c])
{
bo[a][b][c]=;
q[++tail]=cnt;
e[++cnt].a=a;
e[cnt].b=b;
e[cnt].c=c;
}
a-=temp;c+=temp; temp=min(a,B-b);//a2b
a-=temp;b+=temp;
if(!bo[a][b][c])
{
bo[a][b][c]=;
q[++tail]=cnt;
e[++cnt].a=a;
e[cnt].b=b;
e[cnt].c=c;
}
a+=temp;b-=temp; temp=min(A-a,b);//b2a
a+=temp;b-=temp;
if(!bo[a][b][c])
{
bo[a][b][c]=;
q[++tail]=cnt;
e[++cnt].a=a;
e[cnt].b=b;
e[cnt].c=c;
}
a-=temp;b+=temp; temp=min(b,C-c);//b2c
b-=temp;c+=temp;
if(!bo[a][b][c])
{
bo[a][b][c]=;
q[++tail]=cnt;
e[++cnt].a=a;
e[cnt].b=b;
e[cnt].c=c;
}
b+=temp;c-=temp; temp=min(c,B-b);//c2b
c-=temp;b+=temp;
if(!bo[a][b][c])
{
bo[a][b][c]=;
q[++tail]=cnt;
e[++cnt].a=a;
e[cnt].b=b;
e[cnt].c=c;
}
b-=temp;c+=temp;
}
int firflag=;
for(int i=;i<=C;i++)
{
b=C-i;
if(bo[][b][i])
if(firflag)
printf("%d",i),firflag=;
else printf(" %d",i);
}
printf("\n");
return ;
}

对了,输出格式很重要,提交前别忘记检查,血与泪的教训

USACO 1.4 Mother's Milk的更多相关文章

  1. USACO Section1.4 Mother's Milk 解题报告

    milk3解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  2. USACO training course Mother's Milk /// DFS(有点意思) oj10120

    题目大意: 输入 A B C 为三个容器的容量 一开始A B是空的 C是满的 每一次倾倒只能在 盛的容器满 或 倒的容器空 时才停止 输出当A容器空时 C容器内剩余量的所有可能值 Sample Inp ...

  3. 洛谷P1215 [USACO1.4]母亲的牛奶 Mother's Milk

    P1215 [USACO1.4]母亲的牛奶 Mother's Milk 217通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 ...

  4. P1215 [USACO1.4]母亲的牛奶 Mother's Milk

    P1215 [USACO1.4]母亲的牛奶 Mother's Milk 题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满 ...

  5. 【USACO 1.4】Mother's Milk

    /* TASK: milk3 LANG: C++ SOLVE: 倒水,dfs,枚举每一种倒法,ca[i][j]记录a和c桶的状态,因为总体积不变,故b的状态不需要记录. */ #include< ...

  6. USACO Section 1.4 Mother's Milk 解题报告

    题目 题目描述 有三个牛奶桶,三个桶的容积分别是A,B,C,最小为1,最大为20.刚开始只有第三个桶里面装满了牛奶,其余两个桶都是空的.我们现在可以将第三个桶中的牛奶往其他两个桶里面倒一些牛奶,然后还 ...

  7. Section 1.4 Mother's Milk

    又是一道怨念已久的题目0 0之前深搜写过广搜写过,怎么就是卡死,我还以为FP坏了重新装了一遍.今天偶尔翻起来,发现广搜忘记inc(head)了…简直哭瞎… 简单的广搜,分类比较多,不过不太要动脑子.至 ...

  8. USACO Section 1.3 Mixing Milk 解题报告

    题目 题目描述 Merry Milk Makers 公司的业务是销售牛奶.它从农夫那里收购N单位的牛奶,然后销售出去.现在有M个农夫,每个农夫都存有一定量的牛奶,而且每个农夫都会有自己的定价.假设所有 ...

  9. luogu P1215 [USACO1.4]母亲的牛奶 Mother's Milk

    题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到另一个桶中,直到被灌桶装满或原桶空了 ...

随机推荐

  1. 阿里云 linux centos 常用解压命令

    格式:  tar  选项  文件目录列表     功能:  对文件目录进行打包备份     选项: -c 建立新的归档文件 -r 向归档文件末尾追加文件 -x 从归档文件中解出文件 -O 将文件解开到 ...

  2. C# 线程知识汇总

    一.基本概念 进程(process)是windows系统中你的一个基本概念,它包含着一个运行程序所需要的资源.一个正在运行的应用程序在操作系统中被视为一个进程,进程可以包括一个或者多个线程.线程是操作 ...

  3. 使用光盘作为yum源安装ifconfig等网络命令

    # mkdir -p /mnt/cdrom# 如果是光驱:mount -t iso9660 /dev/cdrom /mnt/cdrom/# 如果是ISO:mount -o loop /usr/loca ...

  4. 读书笔记「Python编程:从入门到实践」_2.变量和简单数据类型

    做了大半年RPA了,用的工具是Kapow. 工作没有那么忙,不想就这么荒废着,想学点什么.就Python吧. 为期三个月,希望能坚持下来. 2.1 变量的命名和使用 变量名只能包含字母.数字和下划线. ...

  5. adb使用实践

    目录 1. adb 端口占用 2. 查看包名和MainAcitivity =============================================================== ...

  6. Github 团队协作基本流程与命令操作 图解git工作流程

    # 先 fork 项目到自己 github # 1. 从自己仓库克隆到本地(clone 的是项目指定的默认分支,比如 master) git clone git@github.com:me/em.gi ...

  7. Laravel5.6安裝:Warning: require(../vendor/autoload.php): failed to open stream: No such file or directory

    在phpstudy下使用composer+laravel安装器的方式安装了Laravel,但是访问的时候报错: Warning: require(D:\phpstudy\WWW\public\mybl ...

  8. 当使用junit4 对spring框架中controller/service/mapper各层进行测试时,需要添加的配置

    @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(locations = {&quo ...

  9. Kattis -Safe Passage(撑伞问题)

    Safe Passage Photo by Ian Burt A group of friends snuck away from their school campus, but now they ...

  10. 【转】【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之RAC 工作原理和相关组件(三)

    原文地址:http://www.cnblogs.com/baiboy/p/orc3.html 阅读目录 目录 RAC 工作原理和相关组件 ClusterWare 架构 RAC 软件结构 集群注册(OC ...