Codeforces Round #345 (Div. 2) A. Joysticks dp
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的更多相关文章
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Codeforces Round #131 (Div. 2) B. Hometask dp
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- 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 ...
- 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 ...
随机推荐
- gpio子系统和pinctrl子系统(中)
pinctrl子系统核心实现分析 pinctrl子系统的内容在drivers/pinctrl文件夹下,主要文件有(建议先看看pinctrl内核文档Documentation/pinctrl.txt): ...
- 手動設定 電池溫度 mtk platform
adb root adb shell echo "3 1 27" > ./proc/mtk_battery_cmd/battery_cmd 27 即是所要設定的溫度, 此設定 ...
- 关闭自动弹出照片自动弹出iTunes以及关闭手机照片流
关闭自动弹出照片自动弹出iTunes以及关闭手机照片流 如何阻止iPhone连接Mac后自动弹出照片? 时间:2015/6/18 17:07:15来源:本站原创作者:Chenjh我要评论 很多新 iP ...
- ASPxgridview 编辑列初始化事件
在初始化编辑咧的时候,给其赋值或者是disable等等.... 贴上代码 protected void master_CellEditorInitialize(object sender, ASPxG ...
- maven使用备忘
maven的所有功能本质上都是通过插件来实现的所有的功能.archetype插件就是根据项目类型创建项目的插件.执行archetype:generate命令就会list一系列的项目类型,可以选择一个合 ...
- Webstorm和Eclipse常用快捷键
快捷键配置 点击“File”-> “settings” Webstorm预置了其他编辑器的快捷键配置,可以点击 默认配置-Eclipse的常用快捷键对照表 查找/代替 Webstorm快捷键 E ...
- redis 的优化
1.pipeling “请求-响应”模式的服务器在处理完一个请求后就开始处理下一个请求,不管客户端是否读取到前一个请求的响应结果.这让客户端不需要发一个请求等一个响应的串行,可以一次发送多个请求,再最 ...
- html,js一个元素做两次不同点击事件
业务需求:一个按钮,第一次点击,修改页面内容,第二次点击,提交修改. 刚开始,我绑定了第一个click事件,用于让右边的内容可编辑.如:$('#id').click(function(){...}); ...
- MySQL-数据操作
阅读目录 一 介绍 二 插入数据INSERT 三 更新数据UPDATE 四 删除数据DELETE 五 查询数据SELECT 回到顶部 一 介绍 MySQL数据操作: DML ============= ...
- 关于获取android6.0的mac地址
原文:http://blog.csdn.net/suziluo123/article/details/51382410 最近接触6.0,发现使用单纯的wifiManager.getConnection ...