CodeForces 651 A 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
#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的更多相关文章
- 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 651 C Watchmen
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces 651 C. Watchmen-曼哈顿距离和欧几里得距离
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces 651 B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #345 (Div. 2) A. Joysticks dp
A. Joysticks 题目连接: http://www.codeforces.com/contest/651/problem/A Description Friends are going to ...
- CodeForces 651A Joysticks 贪心
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 651A Joysticks
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 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 ...
随机推荐
- UIImageView的一些用法
转自:http://blog.sina.com.cn/s/blog_60e2dbcf01014bfm.html //初始化 UIImageView *imageView=[[UIImageView ...
- python3+spark2.1+kafka0.8+sparkStreaming
python代码: import time from pyspark import SparkContext from pyspark.streaming import StreamingContex ...
- Linux Ubuntu 打开.exe文件
这两天在编译Android源码,进行到要在Linux里安装烧录软件那一步,要先装驱动,故了解了如何在linux下打开.exe文件. .exe 文件在linux下不能直接打开,可有两种方式打开:. 1. ...
- spring 注解@Resource @Autowired区别
1.@Autowired寻找类的时候默认是ByType,也就是通过类的类型来寻找类.不过,也可以通过借助@Qualifier("name")来指定寻找的类名 @Autowired ...
- pentestbox使用教程
pentestbox工具列表:https://tools.pentestbox.org/ freebuf入门实战:http://www.freebuf.com/sectool/125881.html ...
- PLSQL 连接不上64位ORACLE数据库解决办法
http://it.oyksoft.com/post/6003/ huan jing bian liang TNS_ADMIN D:\OracleClient D:\OracleClient\TNS ...
- 数据库 Proc编程二
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...
- tp 批量转码
读取王正东成功,然后把乱码一条一条的改回来... 专门针对mssql数据库的!!!
- 【BZOJ】1037: [ZJOI2008]生日聚会Party(递推+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1037 看来自己越来越弱了... 这些计数题设计的状态都很巧妙,,自己智商太低QAQ 和矩阵dp做的那 ...
- 【BZOJ】1690: [Usaco2007 Dec]奶牛的旅行(分数规划+spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1690 第一题不是水题的题.. 分数规划.. T-T 百度吧..http://blog.csdn.ne ...