CodeForces - 651A Joysticks ( 不难 但有坑 )
正式更换编译器为: VS Code
如何配置环境:click here
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
题意
你有两个手机,和一个充电器,如果手机插上充电器,每秒涨%1的电,如果不插充电器,每秒掉%2的电
问你最多能维持多久两个手机都有电。
可以超过100%
题解
一:DP
dp[i][j]表示第一个手机有i的电,第二个手机有j的电最长能够坚持多久
然后特判一下1 1的情况就好了。
// Author : RioTian
// Time : 20/10/14
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[320][320], 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() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int a, b;
cin >> a >> b;
if (a == 1 && b == 1)
cout << 0 << endl;
else
cout << solve(a, b) << endl;
}
二:数学
// Author : RioTian
// Time : 20/10/14
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int a, b; cin >> a >> b;
cout << ((a + b == 2) ? 0 : a + b - 2 - !(a - b) % 3) << endl;
}
三:模拟
// Author : RioTian
// Time : 20/10/14
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int a, b, cnt = 0;
cin >> a >> b;
while (a > 0 && b > 0) {
if (a < 2 && b < 2) break;
if (a < b) swap(a, b);
a -= 2, b++, cnt++;
}
cout << cnt << endl;
}
CodeForces - 651A Joysticks ( 不难 但有坑 )的更多相关文章
- 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 651A Joysticks【贪心】
题意: 两根操纵杆,每分钟操纵杆消耗电量2%,每分钟又可以给一个操纵杆充电1%(电量可以超过100%),当任何一个操纵杆电量降到0时,游戏停止.问最长游戏时间. 分析: 贪心,每次选择电量剩余最少的充 ...
- 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 651a oysticks
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status De ...
- CodeForces 651A(水题)
Friends are going to play console. They have two joysticks and only one charger for them. Initially ...
- [刷题codeforces]651B/651A
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...
- Codeforces Round 504
(交互题真神奇,,,我自己瞎写了一发目测样例都没过去就AC了...) (只出了两题的竟然没掉下蓝名真是可怕) A:我的代码太不美观了,放个同学的(因为我是c++63分的蒟蒻所以根本不知道那些函数怎么用 ...
- 【Java并发】JUC—ReentrantReadWriteLock有坑,小心读锁!
好长一段时间前,某些场景需要JUC的读写锁,但在某个时刻内读写线程都报超时预警(长时间无响应),看起来像是锁竞争过程中出现死锁(我猜).经过排查项目并没有能造成死锁的可疑之处,因为业务代码并不复杂(仅 ...
随机推荐
- Vue07-Axios
Axios axios是一个网络请求相关的库. axios: ajax i/o system 使用axios编写的网络请求代码,可以运行在浏览器端,也可以在Node环境中运行. 01. 支持的请求方式 ...
- 关于Maven执行mvn help:system命令报错
报错: [ERROR] Error executing Maven.[ERROR] 2 problems were encountered while building the effective s ...
- Java连接phoenix问题
这个错误的原因是找不到文件,所以要在本地配置一下hadoop的环境变量 下载 将其中hadoop 这个文件放在c盘windows下system32目录下就ok了
- 这些 git 高级命令你知道几个
大家好,我是 dom 哥.今天给大家分享几个 git 的高级应用. git 是目前最流行的版本控制工具.git 玩的 6 不 6,轻则影响自己的开发幸福指数 ,重则影响下班时间 .本文介绍一些日常开发 ...
- 聊聊流式数据湖Paimon(四)
Partial Update 数据打宽 通过不同的流写不同的字段,打宽了数据的维度,填充了数据内容:如下所示: --FlinkSQL参数设置 set `table.dynamic-table-opti ...
- MinIO客户端之share
MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc share mc share download mc share upload 生成下载对象的URL,指定对 ...
- JavaFx css样式(三)
JavaFx css样式(三) JavaFX 从入门入门到入土系列 JavaFx css样式,前面我说过它类似html,他有css控制样式,不过最新的css标准并不支持,同时javafx的css样式都 ...
- ubuntu 之 go+/goplus 安装
目前情况是要安装 goplus/go+ 之前 必须先安装 golang golang下载地址:https://golang.google.cn/dl/ 或者 https://studygolang.c ...
- MIGO新增页签增强
1.文档说明 本方法是将新增字段,展示在MIGO的新增页签中,并保存到自建表. 新增页签的方法,和采购订单新增页签的方法原理基本一致,都是需要创建函数组,并实现相应方法和屏幕,并在增强中调用该函数组, ...
- UDP与KCP详解
UDP 以及TCP是什么.我们知道传输层中有TCP和UDP两种网络协议,这节就讲UDP是什么. Internet协议集支持一个无连接的传输协议,该协议称为用户数据报协议(UDP,User Datagr ...