Codeforces #345 Div.2 A Joysticks 暴力模拟
2016-03-08 17:17
441 查看
有两个操纵杆,和他们的初始电量,和一个充电器,但充电器在每一分钟内只能给一个操纵杆充电,操纵杆如果被充电,一分钟会增加1%的电量,如果没被充电,一分钟会消耗2%的电量,充电器的电量是无限的,操纵杆的电量也可超过100%,当一个操纵杆电量只剩1%且下一分钟不被充电的话,就使用完毕了,或者当一个操纵杆的电量到达0%,则自动使用完毕。
给两个初始电量a1,a2,求最长使用时间。
题解,想了想,其实中间过程不管怎么充电都可以,但是当其中一个到达1%或2%时,就必须给它充电,不然就会结束。所以我的方案是,谁的电量少,就给谁充电。
那么,什么时候结束呢?1,当有至少一个是0%时,自动结束了。2,当两个都是1%时,两个都需要充啊,但是只能充一个,也就结束了。
代码:
给两个初始电量a1,a2,求最长使用时间。
题解,想了想,其实中间过程不管怎么充电都可以,但是当其中一个到达1%或2%时,就必须给它充电,不然就会结束。所以我的方案是,谁的电量少,就给谁充电。
那么,什么时候结束呢?1,当有至少一个是0%时,自动结束了。2,当两个都是1%时,两个都需要充啊,但是只能充一个,也就结束了。
代码:
#include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <string> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int main() { //freopen("input.txt", "r", stdin); int a1, a2, ans = 0; scanf("%d%d", &a1, &a2); while (1) { if ((a1 == 1 && a2 == 1) || a1 == 0 || a2 == 0) break; if (a1 <= a2) { ++a1; a2 -= 2; ++ans; } else { ++a2; a1 -= 2; ++ans; } } printf("%d\n", ans); //while (1); //system("pause"); return 0; }
相关文章推荐
- oracle12c 的SYSBACKUP、SYSDG、SYSKM系统用户
- Android 控件使用教程(二)—— RecyclerView 展示图片
- IE8+兼容经验小结
- js如何判断一个对象是不是Array
- Mybatis-Generator 自动生成Dao、Model、Mapping相关文档
- Mybatis-Generator 详解 http://www.cnblogs.com/jtzfeng/p/5254798.html
- U-boot启动过程
- Centos7中hadoop2的eclipse开发环境配置
- [leetcode] 235. Lowest Common Ancestor of a Binary Search Tree
- redis缓存技术学习
- 自定义MyBatis返回Map对象
- easyui主界面分析-3
- Android Studio 小技巧合集
- 4.交叉编译
- js中Math方法的小技巧
- 详解Nginx配置nginx.conf
- linux上访问页面
- POJ 1006 Biorhythms(中国剩余定理互质版本)
- 分享一种用户密码加密方式解析
- [国嵌攻略][120][按键驱动硬件操作实现]