正式更换编译器为: VS Code

如何配置环境:click here

代码格式化工具:clang-format

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 ( 不难 但有坑 )的更多相关文章

  1. CodeForces 651A Joysticks 贪心

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

  2. codeforces 651A Joysticks

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

  3. Codeforces 651A Joysticks【贪心】

    题意: 两根操纵杆,每分钟操纵杆消耗电量2%,每分钟又可以给一个操纵杆充电1%(电量可以超过100%),当任何一个操纵杆电量降到0时,游戏停止.问最长游戏时间. 分析: 贪心,每次选择电量剩余最少的充 ...

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

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

  5. 【CodeForces 651A】Joysticks 模拟

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

  6. codeforces 651a oysticks

      Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status De ...

  7. CodeForces 651A(水题)

    Friends are going to play console. They have two joysticks and only one charger for them. Initially ...

  8. [刷题codeforces]651B/651A

    651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...

  9. Codeforces Round 504

    (交互题真神奇,,,我自己瞎写了一发目测样例都没过去就AC了...) (只出了两题的竟然没掉下蓝名真是可怕) A:我的代码太不美观了,放个同学的(因为我是c++63分的蒟蒻所以根本不知道那些函数怎么用 ...

  10. 【Java并发】JUC—ReentrantReadWriteLock有坑,小心读锁!

    好长一段时间前,某些场景需要JUC的读写锁,但在某个时刻内读写线程都报超时预警(长时间无响应),看起来像是锁竞争过程中出现死锁(我猜).经过排查项目并没有能造成死锁的可疑之处,因为业务代码并不复杂(仅 ...

随机推荐

  1. [JDK/APM] 应用诊断工具之VisualVM

    1 概述 1.1 简介 VisualVM is a visual tool integrating commandline JDK tools and lightweight profiling ca ...

  2. Python 潮流周刊第 30 期(摘要)

    本周刊由 Python猫 出品,精心筛选国内外的 250+ 信息源,为你挑选最值得分享的文章.教程.开源项目.软件工具.播客和视频.热门话题等内容.愿景:帮助所有读者精进 Python 技术,并增长职 ...

  3. VSCode个性化的配置

    1.下载插件 Eclipse快捷键(我以前用Eclipse习惯了,大家不需要) Premitter Vetur koroFileHeader 2.修改VSCode设置 3.粘贴下面的代码 { &quo ...

  4. 【2020】装了VirtualBox后VMware Workstation无法使用SSH连接Centos的解决方法

    装了个VirtualBox,然后发现无法使用Xshell远程Vmware中的centos了,一开始感觉是虚拟网卡冲突了,发现把VirtualBox的虚拟网卡禁用就可以使用,但是好麻烦啊??每次我特么要 ...

  5. 数字孪生为何通过融合GIS系统能够更好地助力智慧城市发展?

    随着城市化进程的不断加速,智慧城市建设已成为许多城市发展的重要方向.在智慧城市中,数字孪生技术和GIS系统的融合,为城市发展带来了全新的可能性和机遇.数字孪生是一种将物理世界和数字世界相结合的技术,通 ...

  6. 数字孪生结合GIS会给矿业带来怎样的改变

    数字孪生技术和GIS的结合为矿业带来了革命性的改变.矿业作为重要的经济支柱,其发展与资源的开采.生产过程的管理密切相关.通过数字孪生和GIS的融合,矿业行业可以实现更高效.可持续的运营和管理,带来许多 ...

  7. apache+mysql+php环境安装及配置

    一.安装mysql 1.yum安装mysql # yum -y install mysql mysql-server 2.安装mariadb,用mariadb来启动数据库,systemctl star ...

  8. selenium之三种等待,强制等待、隐式等待和显式等待

    显式等待 presence_of_element_locatedpresence_of_all_elements_locatedvisibility_of_any_elements_located   ...

  9. 虚拟化H搭建

    虚拟化H搭建 H搭建所需要的硬件配置 最大值:所有组件不能超过160个cpu 按安装H需要2G内存+若干个guest(不明确多大),最大支持2个TB内存 最小磁盘2G 一个千兆网卡 lscpu信息 [ ...

  10. [Luogu 4912 帕秋莉的魔法] 题解报告

    算法:DP, 背包,动态规划 简化版题目: 给定 \(n\) 个物品,物品的价值为 \(v_1 - v_n\),物品的体积为 \(w_1 - w_n\).需要选择一些物品,使它们的体积和为 \(V\) ...