CodeForces 651A Joysticks 贪心
1 second
256 megabytes
standard input
standard output
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).
Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
- 3 5
- 6
- 4 4
- 5
- 题目大意:有两个手柄,我们会给出他剩余的电量,每次充电一分钟会多百分之一的电量,不充点会掉百分之二的电。
思路:贪心,优先选择电量少的充,注意两个手柄电量为1时特殊情况
- #include <stdio.h>
- int main()
- {
- int a ,b, t=;
- scanf("%d%d", &a, &b);
- while(a>=&&b>=)
- {
- if(a==&&b==)
- break;
- if(a>b)
- {
- a -= ;
- b++;
- t++;
- }
- else
- {
- b -= ;
- a++;
- t++;
- }
- }
- printf ("%d\n", t);
- return ;
- }
CodeForces 651A Joysticks 贪心的更多相关文章
- Codeforces 651A Joysticks【贪心】
题意: 两根操纵杆,每分钟操纵杆消耗电量2%,每分钟又可以给一个操纵杆充电1%(电量可以超过100%),当任何一个操纵杆电量降到0时,游戏停止.问最长游戏时间. 分析: 贪心,每次选择电量剩余最少的充 ...
- codeforces 651A Joysticks
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- CodeForces - 158B.Taxi (贪心)
CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...
- codeforces 651A A. Joysticks (模拟)
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 【CodeForces 651A】Joysticks 模拟
题意:给定a,b,每个单位时间可以将a,b中一台加1,一台减2,求最久可以支持多久. #include <cstdio> #include <algorithm> using ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- Codeforces 626G Raffles(贪心+线段树)
G. Raffles time limit per test:5 seconds memory limit per test:256 megabytes input:standard input ou ...
- Cut 'em all! CodeForces - 982C(贪心dfs)
K - Cut 'em all! CodeForces - 982C 给一棵树 求最多能切几条边使剩下的子树都有偶数个节点 如果n是奇数 那么奇数=偶数+奇数 不管怎么切 都会有奇数 直接打印-1 贪 ...
- CodeForces - 940E - Cashback +贪心+DP
传送门:CodeForces - 940E - Cashback 题意:在一个长度为n的数组中,可以分出长度为 k 连续的多个数组b(每个数组 b 的 k 可不相同),然后,可以对每个数组 b 进行删 ...
随机推荐
- 怎么查看windows2003中隐藏用户
在命令模式下删除1.你在MS-dos下先输入net user 看有那些用户, 注意第一步看不出隐藏的用户 2.然后在输入net localgroup administrators 或者 net loc ...
- 夺命雷公狗—angularjs—3—表单验证的高级用法
其实我们的angularjs都是是块状代码,其实是可以在实际开发中保存下来以后就可以达到重复利用的目的了.. 废话不多说,直接上代码: <!doctype html> <html l ...
- Logic Bist Arch
一般现在多用的都是offline BIST的架构,可以分为4大类: 1)those assume no special structure to the circuit under test; 2)t ...
- 学点儿c#语言wpf开发
首发:个人博客,更新&纠错&回复 visual studio 2015,界面越来越漂亮了. 比起swift和python啥的,还是c#外观上更像java,windows的界面编程,wp ...
- 批处理命令——rem 和 pause
[1]rem命令简介 注释命令,在C语言中相当于/*----------*/,它并不会被执行,只是起到一个注释的作用,便于别人及自己将来阅读和维护脚本. 为了更具体的理解,请看示例: 新建一个文本文件 ...
- linux 程序或服务开机自启动
chkconfig --level 35 服务名 on或写启动脚本到/etc/rc.local/下
- 鸟哥的Linux私房菜之学习shell script
运行程序的时候一般都是创建一个子程序来执行,所以子程序中的变量什么的在当前的shell下没法使用,但是如果使用source来执行就可以在当前shell下执行程序 shift 1 去掉第一个参数,后面接 ...
- django models使用学习记录
如何更新单个数据 example = User.objects.get(id=1) example.is_acitve=1 example.save() 如何更新多个数据 examples = Use ...
- Linux下串口编程【转】
本文转载自:http://blog.csdn.net/w282529350/article/details/7378388 /************声明:本人只是见到这篇文章对我帮助很大才转载的,但 ...
- python 去除字符串中连续的空格,并使用其他的分隔符替代连续的空格
例:1: filt函数用法及匿名函数lamda用法,详见http://www.cnblogs.com/apple2016/p/5657698.html join()用法详见http://www.cnb ...