cf1036 B 思维

题意:https://www.luogu.com.cn/problem/CF1036B

思路:首先考虑直接从起点到终点最多有多少滑步,可以发现坐标差为奇数的时候那么一定需要一步去走掉,所以我们奇数的时候为max-1,偶数为max(大的坐标)。然后我们考虑剩下的步怎么走,如果是偶数我们直接来回滑步即可,那么如果是奇数步呢,这个时候我们回归前面奇偶,奇数的时候我们可以用一个滑步加直走代替前面的奇数直走,那么最后的答案就是k-1。然后我们看偶数,偶数如果剩奇数步我们就用两个直走代替一个滑步,那么答案就是k-2。剩下的情况都是k。

/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
signed main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n, m, k;
		cin >> n >> m >> k;
		int mx = max(n, m);
		int mi = min(n, m);
		if (mx > k) {
			cout << "-1" << endl;
		} else {
			if ((mx - mi) % 2 != 0) {
				cout << k - 1 << endl;
			} else {
				k -= mx;
				if (k % 2) {
					cout << (k + mx) - 2 << endl;
				} else {
					cout << k + mx << endl;
				}
			}
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值