ZOJ 1005 Jugs
题目大意:有一大一小两个杯子,相互倒水,直到其中一个杯子里剩下特定体积的水。描述这个过程。
解法:因为两个杯子的容积互质,所以只要用小杯子不断往大杯子倒水,大杯子灌满后就清空,大杯子里迟早会出现需要的体积的水。不过也有可能小杯子先剩下符合要求的体积的水。
参考代码:
#include<iostream>
using namespace std;
int main(){
int ca,cb,n,q,r,i;
int a,b;
while(cin>>ca>>cb>>n){
a=0;
b=0;
while(1){
if(a==0){
a=ca;
cout<<"fill A"<<endl;
}
if(a+b>cb){
a=a+b-cb;
b=cb;
cout<<"pour A B"<<endl;
}
else{
b=a+b;
a=0;
cout<<"pour A B"<<endl;
}
if(b==n){
cout<<"success"<<endl;
break;
}
if(b==cb){
b=0;
cout<<"empty B"<<endl;
}
}
}
return 0;
}
ZOJ 1005 Jugs的更多相关文章
- ZOJ 1005 Jugs(BFS)
Jugs In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with th ...
- [ZOJ 1005] Jugs (dfs倒水问题)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5 题目大意:给你6种操作,3个数a,b,n,代表我有两个杯子,第一个杯 ...
- ZOJ 1005:Jugs(思维)
Jugs Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In the movie "Die Har ...
- A - Jugs ZOJ - 1005 (模拟)
题目链接:https://cn.vjudge.net/contest/281037#problem/A 题目大意:给你a,b,n.a代表第一个杯子的容量,b代表第二个杯子的容量,然后一共有6种操作.让 ...
- 1005 Jugs
辗转相减,新手入门题.两个容量的灌水题,无所谓最优解. #include<stdio.h> int main(){ int A,B,T,sA,sB; ){ sA=sB=; ){ ){ pr ...
- Jugs(回溯法)
ZOJ Problem Set - 1005 Jugs Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- ZOJ Problem Set - 1005
注意,条件:B>=C .应考虑B=C的情况. #include<iostream> using namespace std; int A,B,C; void jugs(int a,i ...
随机推荐
- c++普通高精除单精
//没有在网上测试 //手测几组无误 //如有错误,还望指出,不胜感激. #include<cstdio>#include<cstring>int a1[600],a2,a4[ ...
- POJ 2771 二分图(最大独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5244 Accepted: 21 ...
- hdu 4612 Warm up
http://acm.hdu.edu.cn/showproblem.php?pid=4612 将原图进行缩点 变成一个树 树上每条边都是一个桥 然后加一条边要加在树的直径两端才最优 代码: #incl ...
- node cheerio
所谓工欲善其事,必先利其器,所以通读了cheerio的API,顺便翻译了一遍,有些地方因为知道的比较少,不知道什么意思,保留了英文,希望各位不吝告诉我,然后一起把这个翻译完成. ###cheerio ...
- Js中 关于top、clientTop、scrollTop、offsetTop的用法
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- Python应用与实践
http://www.cnblogs.com/skynet/archive/2013/05/06/3063245.html
- SrcollView分页加载数据(第二种方法 自定义listView)
package com.baidu.ms; import android.content.Context;import android.util.AttributeSet;import android ...
- Installing Cygwin and Starting the SSH Daemon
This chapter explains how to install Cygwin and start the SSH daemon on Microsoft Windows hosts. Thi ...
- Line计划今年全面进军中国市场:建立本地团队
北京时间6月13日下午消息,<华尔街日报>报道称,移动消息应用Line计划于今年晚些时候进军中国市场.Line将在中国建立本地团队,开发内容和功能,从而进一步开拓中国这一全球最大的移动市场 ...
- Ajax方法实现登录页面
Note: ajax技术 不用刷新页面,做局部刷新不用form表单,因为不需要提交,通过JQuery控制必须要有id如果要用ajax可以用JQuery也可以用js写,推荐JQuery 因为简单,直接引 ...