A. Joysticks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

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.

Examples
input
3 5
output
6
input
4 4
output

5

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
long long int dp[205][205];
int n,m;
long long int dfs(int x,int y)
{
//cout<<x<<" "<<y<<endl;
if(dp[x][y]!=-1)
return dp[x][y];
if(x-2<0&&y-2>=0)
dp[x][y]=dfs(x+1,y-2)+1;
else if(x-2>=0&&y-2<0)
dp[x][y]=dfs(x-2,y+1)+1;
else
{
dp[x][y]=max(dfs(x+1,y-2),dfs(x-2,y+1));
dp[x][y]++;
} return dp[x][y];
}
int main()
{
memset(dp,-1,sizeof(dp));
for(int i=1;i<=100;i++)
dp[i][0]=0,dp[0][i]=0;
dp[1][1]=0;
scanf("%d%d",&n,&m);
printf("%lld\n",dfs(n,m));
return 0;
}

CodeForces 651 A Joysticks的更多相关文章

  1. codeforces 651A A. Joysticks (模拟)

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

  2. 【CodeForces 651A】Joysticks 模拟

    题意:给定a,b,每个单位时间可以将a,b中一台加1,一台减2,求最久可以支持多久. #include <cstdio> #include <algorithm> using ...

  3. CodeForces 651 C Watchmen

    C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  4. Codeforces 651 C. Watchmen-曼哈顿距离和欧几里得距离

    C. Watchmen   time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces 651 B. Beautiful Paintings

    B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. Codeforces Round #345 (Div. 2) A. Joysticks dp

    A. Joysticks 题目连接: http://www.codeforces.com/contest/651/problem/A Description Friends are going to ...

  7. CodeForces 651A Joysticks 贪心

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

  8. codeforces 651A Joysticks

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

  9. 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 ...

随机推荐

  1. PHP域名whois查询代码(数据源万网、新网)

    对于whois查询,数据来自万网.新网,数据也比较权威,需要的朋友可以参考下. 万网 whois(使用的接口为万网提供合法接口) function whois_hichina($domain) {  ...

  2. X86平台简称

    1.PCH:PCH全称为Platform Controller Hub,是intel公司的集成南桥.AMD SB700/710/750  http://support.amd.com/TechDocs ...

  3. 优化神器 beamoff

    http://files.cnblogs.com/files/yipu/beamoff.zip csdn上有下载:http://download.csdn.net/download/bytige/83 ...

  4. sim900GPRS模块ppp拨号上网

    --------------------------------------------- 主机操作系统:Centos 6.5 交叉编译器环境:arm-linux-gcc-4.5.4 开发板平台: F ...

  5. tableview 与 tableview cell

    1.tableview cell: import Foundationimport UIKit class CjwtCell: UITableViewCell { @IBOutlet var lb_c ...

  6. 从乌云的错误漏洞分析看Mifare Classic安全

    前言 12年2月初国内著名安全问题反馈平台-乌云发布了有关某公司员工卡的金额效验算法破解的安全问题.从整个漏洞分析来看,漏洞的提交者把员工卡的数据分析得非常仔细,以至很多刚刚接触或者未曾接触的都纷纷赞 ...

  7. Linux samba 服务的配置

    今天有个学生问我 samba 服务怎么配置,所以晚上特意研究一下怎么配置这个服务. 过程如下: sudo apt-get install samba samba-common // 安装 samba ...

  8. PHP——面向对象

    <body> <?php //类调用用:: //对象调用用-> class Dog1//定义类 { //成员属性(变量) var $name; var $age; var $p ...

  9. SAN和NAS的区别: 层次不一样

    SAN : STORAGE AREA NETWORK   存储区域网络 NAS : NETWORK ATTACHED STORAGE 网络附加存储 NAS不一定是盘阵,一台普通的主机就可以做出NAS, ...

  10. 通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术

    通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages( JSP)技术.Velocity.Tiles.iText 和 POI.Spring MVC ...