usaco1.4.2 Mother's Milk
来源:互联网 发布:js怎么把数字变成汉字 编辑:程序博客网 时间:2024/06/03 18:18
一. 原题
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
二. 分析
三. 代码
USER: Qi Shen [maxkibb3]TASK: milk3LANG: C++Compiling...Compile: OKExecuting... Test 1: TEST OK [0.000 secs, 4188 KB] Test 2: TEST OK [0.000 secs, 4188 KB] Test 3: TEST OK [0.000 secs, 4188 KB] Test 4: TEST OK [0.000 secs, 4188 KB] Test 5: TEST OK [0.000 secs, 4188 KB] Test 6: TEST OK [0.000 secs, 4188 KB] Test 7: TEST OK [0.000 secs, 4188 KB] Test 8: TEST OK [0.000 secs, 4188 KB] Test 9: TEST OK [0.000 secs, 4188 KB] Test 10: TEST OK [0.000 secs, 4188 KB]All tests OK.YOUR PROGRAM ('milk3') WORKED FIRST TIME! That's fantastic-- and a rare thing. Please accept these special automatedcongratulations.
/*ID:maxkibb3LANG:C++PROG:milk3*/#include<cstdio>int v[3];int a[3];bool vis[21][21][21];int min(int a, int b) {return (a < b)?a:b;}void dfs(int x[3]) {if(vis[x[0]][x[1]][x[2]]) return;vis[x[0]][x[1]][x[2]] = true;for(int i = 0; i < 3; i++) {for(int j = 0; j < 3; j++) {if(i == j) continue;if(x[i] != 0 && x[j] != v[j]) {int amt = min(x[i], v[j] - x[j]);x[i] -= amt; x[j] += amt;dfs(x);x[i] += amt; x[j] -= amt;}}}}int main() {freopen("milk3.in", "r", stdin);freopen("milk3.out", "w", stdout);scanf("%d%d%d", &v[0], &v[1], &v[2]);a[0] = a[1] = 0; a[2] = v[2];dfs(a);for(int i = 0; i < v[2]; i++) {for(int j = 0; j <= v[2]; j++) {if(vis[0][j][i]) {printf("%d ", i);break;}}}printf("%d\n", v[2]);return 0;}
- usaco1.4.2 Mother's Milk
- USACO1.4.2 Mother's Milk (milk3)
- USACO1.4.2 Mother's Milk (milk3)
- USACO1.4 母亲的牛奶 Mother's Milk
- P1215 [USACO1.4]母亲的牛奶 Mother's Milk
- 洛谷 1215 [USACO1.4]母亲的牛奶 Mother's Milk
- [USACO1.4]母亲的牛奶Mother's Milk dfs
- Mother's Milk(usaco)
- 1.4Mother's Milk
- Mother's Milk
- Mother's Milk
- usaco Mother's Milk
- Mother's Milk
- USACO:Mother's Milk
- Mother's Milk
- Mother's Milk
- USACO-Mother's Milk
- USACO Mother's Milk
- ubuntu安装nvidia显卡驱动(双显卡)
- Atomic:原子变量与原子类
- DUBBO本地搭建及小案例
- 设计模式之工厂模式 & 单例模式(并发生成单例)
- vscode配置JSHint提示工具
- usaco1.4.2 Mother's Milk
- C语言字符与ASCII码的互转,字符和整型的转换
- 120欧姆 50欧姆
- 总结【代码重构】:Backbone.js做一个点击链接,跳过加载图片后即可跳转到效果图片的例子
- Java学习笔记第十天:1_形式参数和返回值的问题深入研究
- C++易错题总结
- leetcode note--leetcode 167 Two Sum II - Input array is sorted
- yarn描述
- charles 教程0x01-抓包并Mock数据