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)

  1. 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. 1 2 8 9 10

SAMPLE INPUT (file milk3.in)

  1. 2 5 10

SAMPLE OUTPUT (file milk3.out)

  1. 5 6 7 8 9 10
  2.  
  3. 题目大意:倒牛奶。。。。你有三个筒子ABC会告诉你容积,开始的时候AB都是空的,C是满的,问你在不把牛奶倒出三个筒子之外的情况下,在A桶是空的情况下,C桶有多少奶,顺序输出所有可能性。
    思路:没什么说的了,BFS。代码写在下面
  1. /*
  2. ID:fffgrdcc1
  3. PROB:milk3
  4. LANG:C++
  5. */
  6. #include<cstdio>
  7. #include<iostream>
  8. #include<algorithm>
  9. using namespace std;
  10. bool bo[][][]={};
  11. struct str
  12. {
  13. int a,b,c;
  14. }e[];
  15. int cnt=;
  16. int q[],tail,head;
  17. int a,b,c,A,B,C;
  18. int main()
  19. {
  20. freopen("milk3.in","r",stdin);
  21. freopen("milk3.out","w",stdout);
  22. scanf("%d%d%d",&A,&B,&C);
  23. head=-;tail=;e[].a=e[].b=;e[].c=C;q[]=;bo[][][C]=;
  24. while(head<tail)
  25. {
  26. head++;
  27. int temp;
  28. a=e[head].a,b=e[head].b,c=e[head].c;
  29. temp=min(a,C-c);//a2c
  30. a-=temp;c+=temp;
  31. if(!bo[a][b][c])
  32. {
  33. bo[a][b][c]=;
  34. q[++tail]=cnt;
  35. e[++cnt].a=a;
  36. e[cnt].b=b;
  37. e[cnt].c=c;
  38. }
  39. a+=temp;c-=temp;
  40.  
  41. temp=min(A-a,c);//c2a
  42. a+=temp;c-=temp;
  43. if(!bo[a][b][c])
  44. {
  45. bo[a][b][c]=;
  46. q[++tail]=cnt;
  47. e[++cnt].a=a;
  48. e[cnt].b=b;
  49. e[cnt].c=c;
  50. }
  51. a-=temp;c+=temp;
  52.  
  53. temp=min(a,B-b);//a2b
  54. a-=temp;b+=temp;
  55. if(!bo[a][b][c])
  56. {
  57. bo[a][b][c]=;
  58. q[++tail]=cnt;
  59. e[++cnt].a=a;
  60. e[cnt].b=b;
  61. e[cnt].c=c;
  62. }
  63. a+=temp;b-=temp;
  64.  
  65. temp=min(A-a,b);//b2a
  66. a+=temp;b-=temp;
  67. if(!bo[a][b][c])
  68. {
  69. bo[a][b][c]=;
  70. q[++tail]=cnt;
  71. e[++cnt].a=a;
  72. e[cnt].b=b;
  73. e[cnt].c=c;
  74. }
  75. a-=temp;b+=temp;
  76.  
  77. temp=min(b,C-c);//b2c
  78. b-=temp;c+=temp;
  79. if(!bo[a][b][c])
  80. {
  81. bo[a][b][c]=;
  82. q[++tail]=cnt;
  83. e[++cnt].a=a;
  84. e[cnt].b=b;
  85. e[cnt].c=c;
  86. }
  87. b+=temp;c-=temp;
  88.  
  89. temp=min(c,B-b);//c2b
  90. c-=temp;b+=temp;
  91. if(!bo[a][b][c])
  92. {
  93. bo[a][b][c]=;
  94. q[++tail]=cnt;
  95. e[++cnt].a=a;
  96. e[cnt].b=b;
  97. e[cnt].c=c;
  98. }
  99. b-=temp;c+=temp;
  100. }
  101. int firflag=;
  102. for(int i=;i<=C;i++)
  103. {
  104. b=C-i;
  105. if(bo[][b][i])
  106. if(firflag)
  107. printf("%d",i),firflag=;
  108. else printf(" %d",i);
  109. }
  110. printf("\n");
  111. return ;
  112. }

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

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. js---通过arguments来获取指定参数

    通过访问arguments对象的length属性可以获取有多少个参数传递给了函数. 如:每次被调用的时候,输出传入其中的参数个数 function doAdd(){ alert(arguments.l ...

  2. [原创]一道基本ACM试题的启示——多个测试用例的输入问题。

    Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离. Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数 ...

  3. JQuery学习笔记系列(一)----选择器详解

    笔者好长时间没有更新过博客园的笔记了,一部分原因是去年刚刚开始工作一段时间忙碌的加班,体会了一种每天加班到凌晨的充实感,之后闲暇时间了也因为自己懒惰没有坚持记笔记的习惯,现在重新拾起来. 借用古人的一 ...

  4. QS之vsim

    vsim - The vsim command invokes the VSIM simulator -L <library_name> … (optional) Specifies th ...

  5. 八种Docker容器开发模式解析

    原文链接:http://www.csdn.net/article/2014-10-27/2822294 Docker优点已经说过很多次,这里不做详述,Docker现在越来越受到开发人员的青睐,而且利用 ...

  6. 优动漫PAINT发展历程和主要功能

    优动漫PAINT也就是我们常说的clip studio paint(CSP)的中文版本,它是一款功能强大的动漫绘图软件.经过五年的成长,优动漫PAINT经历了从青涩到成熟的发展过程,随着软件更多功能的 ...

  7. JS 100以内的质数、只能被1和自己整除

    for(var i = 2;i <= 100;i++){ var biao = 1; for(var j = 2;j < i;j++){ if(i%j == 0){ biao = 0; } ...

  8. 【leecode】小练习(简单8题)

    def twoSum(nums, target): """ 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[ ...

  9. 通过js 实现 向页面插入js代码并生效,和页面postMessage通讯

       此文章针对已经搭建好jenkins和会使用iconfont图标库而写. 主要目标就是在不通过更改html文件,完成页面交互图标信息,因为美工最多可以上传代码并且自动发布,并不会在Html中加入我 ...

  10. Problem 4

    Problem 4 # Problem_4 """ A palindromic number reads the same both ways. The largest ...