1. 程式人生 > >Codeforces Round #521 (Div. 3) A. Frog Jumping

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; }