zoj 1005 Jugs

/* 今天的ZOJ好卡。。。 一道题提交后几分钟才出来结果 直接模拟即可 大致过程是这样的 如果goal是偶数就先fill B 然后就是把B倒进A 满的话就清空A 然后再把B倒进A 满的话就清空A 直到B空后fill B重复上述过程 或者B中的水==goal时直接跳出 goal是偶数时反过来即可 但是要注意以下几点 按照sample output的提示 应该是只有B中的水==goal时才跳出 还有就是要注意A的容积小于B 所以会出现从B往A中倒水时A满清空了几次 还会出现B中剩余的水大于A的容积的情况 还有一些其他的细节不再一一详述 */ #define LOCAL #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<cctype> #include<iomanip> #include<string> #include<algorithm> #include<ctime> #include<stack> #include<queue> #include<vector> using namespace std; int main() { #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int a,b,ca,cb,goal; while(cin>>ca>>cb>>goal) { a=b=0; if(goal%2==1) { while(1) { a=ca;puts("fill A"); if(a+b<cb) { b+=a;puts("pour A B"); if(b==goal){puts("success");goto out;;} a=0; } else { a=a+b-cb;puts("pour A B"); b=cb; if(b==goal){puts("success");goto out;;} b=0;puts("empty B"); if(b==goal){puts("success");goto out;;} b+=a;puts("pour A B"); if(b==goal){puts("success");goto out;;} a=0; } } } else { while(1) { b=cb;puts("fill B"); if(b==goal){puts("success");goto out;;} if(b+a<ca) { a+=b;puts("pour B A");b=0; if(b==goal){puts("success");goto out;;} } else { while(b+a>goal) { b-=(ca-a);puts("pour B A");a=ca; if(b==goal){puts("success");goto out;} a=0;puts("empty A"); } a=b;puts("pour B A"); b=0; if(b==goal){puts("success");goto out;} } } } out:; } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值