【CodeForces】[651A]Joysticks

文章字数:254

问题描述

问题分析

大意是两个操纵杆一个充电器
每一个分钟只能充一个,充的那个电量+1不充的那个电量-2
需要注意的是
当有一个电量为1时则必须要充
否则就游戏结束
当然 当有电量为0的游戏也结束

所以可以模拟来做
并且考虑一下特殊情况就好了

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h>
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m)!=EOF) {
		int cnt=0;
		while(n&&m) {
			if(n==1&&m>1) {
				n++;
				m-=2;
				cnt++;
			} else if(m==1&&n>1) {
				m++;
				n-=2;
				cnt++;
			} else if(n==1&&m==1) {
				n=0;
				m=0;
			} else {
				if(n>m) {
					int t=(n-m)/2;
					if((n-m)&1)
						t++;
					n-=2*t;
					m+=t;
					cnt+=t;
				} else if(m>n) {
					int t=(m-n)/2;
					if((m-n)&1)
						t++;
					m-=2*t;
					n+=t;
					cnt+=t;
				} else {
					n-=2;
					m++;
					cnt++;
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

题目地址:【CodeForces】[651A]Joysticks

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...