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的情况就好了。

代码

#include<bits/stdc++.h>
using namespace std; int a1,a2;
int dp[320][320];
int vis[320][320];
int solve(int x,int y)
{
if(x>y)swap(x,y);
if(x<=0)return 0;
if(vis[x][y])return dp[x][y];
vis[x][y]=1;
dp[x][y]=max(solve(x-2,y+1),solve(x+1,y-2))+1;
return dp[x][y];
}
int main()
{
cin>>a1>>a2;
if(a1==1&&a2==1)return puts("0"),0;
cout<<solve(a1,a2)<<endl;
}

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. ubuntu下定时弹窗记录工作日志

    背景 记录工作日志,是一个很好的习惯,但不容易坚持,本来打算每天记录,但经常拖延,拖着拖着,有一些事情就忘记了. 等到写周报或月报的时候,才会开始翻邮件,聊天记录,各个仓库的提交log等,回忆都干了些 ...

  2. python并发模块之concurrent.futures(二)

    python并发模块之concurrent.futures(二) 上次我们简单的了解下,模块的一些基本方法和用法,这里我们进一步对concurrent.futures做一个了解和拓展.上次的内容点这. ...

  3. hadoop环境搭建编译

    安装: JDK1.7+ maven 3.0 or later findbugs 1.3.9 protocolBuffer 2.5.0 cmake 2.6 zlib-devel openssl-deve ...

  4. https配置注意细节

    直接将阿里云https的ca配置配置好之后如果不通的话很有可能是防火墙原因造成的,还有就是nginx要用1.10以上版本的

  5. 【Android开发日记】之基础篇(二)——Android的动画效果

          什么是动画,动画的本质是通过连续不断地显示若干图像来产生“动”起来的效果.比如说一个移动的动画,就是在一定的时间段内,以恰当的速率(起码要12帧/秒以上,才会让人产生动起来的错觉)每隔若干 ...

  6. POJ 1456 Supermarket(贪心+并查集)

    题目链接:http://poj.org/problem?id=1456 题目大意:有n件商品,每件商品都有它的价值和截止售卖日期(超过这个日期就不能再卖了).卖一件商品消耗一个单位时间,售卖顺序是可以 ...

  7. php文件上传错误信息

    错误信息说明 UPLOAD_ERR_OK:其值为0,没有错误发生,文件上传成功 UPLOAD_ERR_INI_SIZE:其值为1,上传的文件超过了php.ini和upload_max_filesize ...

  8. hdu 3572(构图+最大流)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. hive的窗口函数1

    Hive中提供了越来越多的分析函数,用于完成负责的统计分析.抽时间将所有的分析窗口函数理一遍,将陆续发布.今天先看几个基础的,SUM.AVG.MIN.MAX.用于实现分组内所有和连续累积的统计. 1. ...

  10. JQuery 获取页面某一元素的位置

    获取页面某一元素的绝对X,Y坐标 var X = $('#ElementID').offset().top; var Y = $('#ElementID').offset().left; 获取相对(父 ...