A. Frog Jumping(水题) Codeforces Round #521 (Div. 3)
原题链接: https://codeforces.com/contest/1077/problem/A

测试样例:
Sample Input
6
5 2 3
100 1 4
1 10 5
1000000000 1 6
1 1 1000000000
1 1 999999999
Sample Output
8
198
-17
2999999997
0
1
解题思路: 一道水题,先往左跳a单位再往右跳b单位,如此反复。跳n次后的坐标,我们只需要考虑n的奇偶性。
AC代码:
/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
ll t,a,b,k,x;
while(cin>>t){
while(t--){
x=0;
cin>>a>>b>>k;
if(k%2==0){
x=(a-b)*(k/2);
}
else{
x=(a-b)*(k/2)+a;
}
cout<<x<<endl;
}
}
return 0;
}

浙公网安备 33010602011771号