Codeforces Round #521 (Div. 3) A. Frog Jumping

题解

题目大意 一个人从0开始偶数向右走a 奇数向左走b 问k次走多远

偶数部分b和a抵消了一部分 奇数再加一个a即可

AC代码

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;

int main()
{
#ifdef LOCAL
	freopen("C:/input.txt", "r", stdin);
#endif
	int T;
	cin >> T;
	while (T--)
	{
		ll a, b, k;
		cin >> a >> b >> k;
		ll ans = (a - b) * (k / 2);
		ans += (k % 2) * a;
		cout << ans << endl;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/CaprYang/article/details/84147693