A. Joysticks

题目连接:

http://www.codeforces.com/contest/651/problem/A

Description

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.

Input

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

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

Sample Input

3 5

Sample Output

6

Hint

题意

你有两个手机,和一个充电器,如果手机插上充电器,每秒涨%1的电,如果不插充电器,每秒掉%2的电

问你最多能维持多久两个手机都有电。

可以超过100%

题解:

我写的是dp,dp[i][j]表示第一个手机有i的电,第二个手机有j的电最长能够坚持多久

然后特判一下1 1的情况就好了。

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a1,a2;
  4. int dp[320][320];
  5. int vis[320][320];
  6. int solve(int x,int y)
  7. {
  8. if(x>y)swap(x,y);
  9. if(x<=0)return 0;
  10. if(vis[x][y])return dp[x][y];
  11. vis[x][y]=1;
  12. dp[x][y]=max(solve(x-2,y+1),solve(x+1,y-2))+1;
  13. return dp[x][y];
  14. }
  15. int main()
  16. {
  17. cin>>a1>>a2;
  18. if(a1==1&&a2==1)return puts("0"),0;
  19. cout<<solve(a1,a2)<<endl;
  20. }

Codeforces Round #345 (Div. 2) A. Joysticks dp的更多相关文章

  1. Codeforces Round #345 (Div. 2)——A. Joysticks(模拟+特判)

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  4. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  5. Codeforces Round #131 (Div. 1) B. Numbers dp

    题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...

  6. Codeforces Round #131 (Div. 2) B. Hometask dp

    题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...

  7. Codeforces Round #276 (Div. 1) D. Kindergarten dp

    D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...

  8. Codeforces Round #260 (Div. 1) A - Boredom DP

    A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A ...

  9. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. shell中的IFS和$*变量

    本文转载自http://blog.chinaunix.net/uid-22566367-id-381955.html 自我记录内容.在工程中遇到了相关内容的shell脚本.在此处记录 STRING1= ...

  2. python基础===解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX(转载)

    本文转自:解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX 从网上抓了一些字 ...

  3. python近期遇到的一些面试问题(一)

    整理一下最近被问到的一些高频率的面试问题.总结一下方便日后复习巩固用,同时希望可以帮助一些朋友们. 1.python的基本数据类型 主要核心类型分为两类不可变类型:数字(int float bool ...

  4. Java单线程多实例和多线程多实例

    最近写了一个程序,是采用多线程往redis里面写入数据,想统计一下一共写了多少条数据,于是用了一个static的全局变量count来累加,这块代码抽象出来就是这样的: public class Mul ...

  5. 用指定jdk执行jar包

    在运行jar包前执行以下命令,作用是在当前命令行窗口作用域内修改环境变量: export JAVA_HOME=/root/jiabao.gao/Hbase2Redis-1.0.0-SNAPSHOT/j ...

  6. maven设置打jar包并引入依赖包

    --------------------------------------------------------方法一:将jar包和项目打在一起---------------------------- ...

  7. 今天开始学模式识别与机器学习(PRML),章节5.1,Neural Networks神经网络-前向网络。

    今天开始学模式识别与机器学习Pattern Recognition and Machine Learning (PRML),章节5.1,Neural Networks神经网络-前向网络. 话说上一次写 ...

  8. BootStrap 实现导航栏nav透明,nav子元素文字不透明

    在给nav 的属性赋值 opacity:0.0透明度时会导致nav内子元素会继承opacity属性.此时再对子元素赋值opacity:1.0 时会导致 子元素实际opacity值为0.0*1.0=0. ...

  9. JMX monitor weblogic 总结

    https://blog.csdn.net/joy_91/article/details/42774839

  10. 急!急!急!请问win32api参数乱码如何解决!

    我想做一个QQ自动登陆,使用的QQ是2009.现在先模拟打开QQ,然后通过api调用回调函数.回调函数为一个委托方法,但是在方法中整个参数乱码,请问如何解决? 具体流程为,启动QQ,获取当前启动QQ的 ...