codeforces 651A Joysticks

广工计组实验f2一位全加器 一位全加器实验 阅读详情

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
Note

In the first sample game lasts for 6 minute by using the following algorithm:

  • at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
  • continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
  • at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
  • continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
  • at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
  • at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.

After that the first joystick is completely discharged and the game is stopped.


题意是两个手柄吧是,然后只能一个充电,充电效率是1%/min,放电效率是2%/min,然后一分钟开始的的时候决定这一分钟是充电还是放电,充电可以充的超过100%,放电的话到0%就结束,或者在一分钟开始的时候应该放电的那个是1%也结束,因为1 - 2 = -1,只能撑半分钟

每分钟有一次机会可以换充放电的手柄,问两个人最长能坚持多长时间

用循环就可以搞定了,就是注意下0%和1%这两种情况就可以了

注意边界1 1输出0,1 2输出1


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	//保证a < b
	if (a > b) {
		int tem = a;
		a = b;
		b = tem;
	}
	int cou = 0;
	//每次都是电量多的放电到不能再放为止才切换充电器
	//如果较大电量<= 1了,就说明这一分钟完不成了
	while (b > 1) {
		if (b - 2 <= 0) {
			cou++;
			break;
		};
		while (b - 2 > 0) {
			b -= 2;
			a += 1;
			cou++;
		}
		//保证a < b
		if (a > b) {
			int tem = a;
			a = b;
			b = tem;
		}
	}
	printf("%d\n", cou);
	return 0;
}





【数据集】中国大气污染物数据集CHAP(1km空间分辨率)-韦晶团队 中国大气污染物数据集CHAP(1km空间分辨率)-韦晶团队 阅读详情

相关推荐

CODESYS开发实战:EtherCAT总线伺服从站配置与运动控制

本文详细介绍了在CODESYS平台上进行EtherCAT总线伺服从站配置与运动控制的实战教程。内容涵盖从设备描述文件安装、主从站拓扑构建,到核心的伺服使能状态机编程、过程数据映射,以及最终实现点位运动控制的完整流程。文章旨在帮助开发者快速掌握基于CODESYS的EtherCAT总线伺服控制技术,提升工业自动化项目开发效率。

weixin_29281915的博客 337

Codeforces 651A Joysticks 【贪心】

题目链接:Codeforces 651A Joysticks

世界很大 842

libero烧录信号抓取

提示:如果改了东西需要重新烧录,需要把这两个界面都关闭再libero打开。两个红色的要关闭掉。然后返回libero开始烧录,观测信号(如果只烧录观测从这一步开始就行)等到下面的messige出现以下信息表示run好了。在下图中右侧可以自己设置,设置完之后记得保存一下。run一下,耐心等待,有警告就ok,run完之后。run成功会变绿色,然后点下面的这个看波形。设置抓取信号:在libero打开。打开的就是烧录界面,直接run。

qq_34047965的博客 1452

Codeforces 651A Joysticks

Codeforces 651A Joysticks题目大意如下: 有两个游戏棒,开始各含有charge[0]和charge[1]的电量,都大于0。现在要使用这两个游戏棒玩游戏,但是如果其中只要有一个游戏棒没有电(也就是0)那么游戏就没有办法进行下去。现在知道只有一个充电口,而且充电只能在每分钟的开始阶段,每分钟可以充入1%的电量,然而玩游戏每分钟会消耗2%的电量(只能一个在充电,一个在玩)。现在

kornberg_fresnel的博客 449

关于 Python PyQt5 界面运行时提示无法初始化Qt平台的解决方案

关于 Python PyQt5 界面运行时提示无法初始化Qt平台的解决方案

smart_num_1的博客 6889

Windows Server下OnlyOffice Workspace社区版安装避坑指南(含局域网邮箱配置)

本文详细介绍了在Windows Server环境下部署OnlyOffice Workspace社区版的完整流程,特别针对企业内网环境中的邮箱配置和端口冲突等常见问题提供了实用解决方案。通过硬件资源配置建议、软件环境检查清单以及内网邮箱系统搭建方案对比,帮助用户高效搭建企业级协作平台,实现团队协作的无缝对接。

weixin_29231263的博客 458

CodeForces - 651A Joysticks

A - Joysticks 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 c...

Wolfgang 286

ServiceNow Discovery & CMDB Interview Questions and Answers (2025)

【代码】ServiceNow Discovery & CMDB Interview Questions and Answers (2025)

weixin_47584092的博客 922

【CodeForces】[651A]Joysticks

大意是两个操纵杆一个充电器 每一个分钟只能充一个,充的那个电量+1不充的那个电量-2 需要注意的是 当有一个电量为1时则必须要充 否则就游戏结束 当然 当有电量为0的游戏也结束所以可以模拟来做 并且考虑一下特殊情况就好了

BoilTask Talk Show 488

Google Earth Engine(GEE)——将sentinel - 2影像所有波段重采样到10m分辨率 (resample 和 projection的使用)

影像重投影是将一个影像从一个坐标系投影到另一个坐标系的过程。这通常涉及到将像素从一个平面坐标系变换到另一个平面坐标系。这可以用于许多应用中,例如建立数字高程模型(DEM)和地图制图。影像重投影通常需要进行数学计算,包括转换矩阵和插值算法,以确保像素值的准确性和精度。这次我们将对哨兵2好数据中20m分辨率的波段,重采样到10m分辨率中,然后同一参与计算。

此星光明博客 3115

OpenClaw 开机自启配置:Windows/macOS/Linux 全平台技术指南

OpenClaw 开机自启全平台配置指南 本文提供了在Windows、macOS和Linux系统上配置OpenClaw开机自启的完整技术方案。主要内容包括: Windows配置:提供三种方法(Windows服务、任务计划程序、启动文件夹),详细说明服务脚本创建、服务注册和测试流程 macOS配置:使用LaunchAgent实现开机自启,包含配置文件创建和加载方法 Linux配置:通过systemd服务实现,包括服务单元文件创建和启用步骤 系统要求:明确硬件(64位CPU/4GB内存)和软件(各平台操作系统版

一键难忘的博客 3009

Joysticks CodeForces - 651A

Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1percent and second one is charged at a2 percent. You can connect char...

weixin_42171215的博客 234

ZYNQ系列PS侧和PL侧DDR3或DDR4在AD(Altium Designer 25)中的layout布线规则约束

DDR3或DDR4的PCB布线规则通常有相对固定的要求,对应的,在PCB设计时有固定的约束设置。

FPGA艺术家的博客 806

Codeforces 651A Joysticks(模拟)

题目:http://codeforces.com/problemset/problem/651/A 代码: #include #include using namespace std; int main() { int a,b; while(~scanf("%d%d",&a,&b)) { int ans=0; if(a==1&&b==

Pig_Me的博客 413

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

CodeForces 651 A Joysticks

CodeForces 651 A Joysticks

Dacc123的博客 669

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

codeforces 651A A. Joysticks

Description Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1percent and second one is charged at a2 percent. You

WOLF的博客 449

inori mmd 7z

楪祈的模型资源....................................................................................................................................................................................................................

Codeforces 651A Joysticks【贪心】

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

An55511的博客 165

codeforces 651A Joysticks【贪心】

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 tw

wyjwyl的专栏 1078

【CodeForces 651A】Joysticks 模拟

题意:给定a,b,每个单位时间可以将a,b中一台加1,一台减2,求最久可以支持多久。#include <cstdio> #include <algorithm> using namespace std;const int N=256;int n1,n2; int cnt;int main(void) { scanf("%d%d",&n1,&n2); while (n1>0&&n2>0

Sdchr 351

Codeforces 651A Joysticks

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 tw

Chunzhen的博客 421

CodeForces 651A:Joysticks【模拟】

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 tw

所谓梦想,就是永不停息的疯狂。。。。。 762

Codeforces 651 A. Joysticks

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

weixin_30376453的博客 116

CodeForces - 651A A. Joysticks

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 tw

Singular__point的博客 462

【贪心】【codeforces】651A Joysticks

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=336194 就是最开始有两个油箱,初始有a1(percent) a1(percent)的油,只有一根加油管,如果加油可以一分钟加1%的油,不加油的那个油箱一分钟会掉2%的油 当有油箱出现没有油的情况时游戏结束,要求找到使游戏时间最长的策略(油箱的油可以超过100%) ...

weixin_30567225的博客 99

CodeForces 651A-Joysticks

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.

小I的博客 423
上一篇: hdu1394 Minimum Inversion Number 最小逆序数 线段树单点更新区间查询
下一篇: codeforces 651B Beautiful Paintings
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址