CF1077A.Frog Jumping
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A frog is currently at the point 0 on a coordinate axis Ox. It jumps by the following algorithm: the first jump is a units to the right, the second jump is b units to the left, the third jump is a units to the right, the fourth jump is b units to the left, and so on.
Formally:
- if the frog has jumped an even number of times (before the current jump), it jumps from its current position x to position x+a;
- otherwise it jumps from its current position x to position x−b.
Your task is to calculate the position of the frog after k jumps.
But... One more thing. You are watching t different frogs so you have to answer t independent queries.
一只青蛙当前位于坐标轴 Ox 上的点 0 处。它按照以下规则跳跃:第一次向右跳 a 个单位,第二次向左跳 b 个单位,第三次向右跳 a 个单位,第四次向左跳 b 个单位,依此类推。
形式化地定义如下:
- 若青蛙在当前跳跃之前已跳跃偶数次,则它从当前位置 x 跳至位置 x+a;
- 否则,它从当前位置 x 跳至位置 x−b。
你的任务是计算青蛙经过 k 次跳跃后的位置。
但是……还有一点:你正在同时观察 t 只不同的青蛙,因此你需要回答 t 个相互独立的查询。
输入格式
The first line of the input contains one integer t (1≤t≤1000) — the number of queries.
Each of the next t lines contain queries (one query per line).
The query is described as three space-separated integers a,b,k (1≤a,b,k≤109) — the lengths of two types of jumps and the number of jumps, respectively.
输入的第一行包含一个整数 t(1≤t≤1000),表示查询次数。
接下来的 t 行每行包含一个查询(每行一个查询)。
每个查询由三个以空格分隔的整数 a,b,k(1≤a,b,k≤109)描述,分别表示两种跳跃的长度以及跳跃总次数。
输出格式
Print t integers. The i-th integer should be the answer for the i-th query.
输出 t 个整数。其中第 i 个整数应为第 i 个查询的答案。
输入输出样例
输入#1
6 5 2 3 100 1 4 1 10 5 1000000000 1 6 1 1 1000000000 1 1 999999999
输出#1
8 198 -17 2999999997 0 1
说明/提示
In the first query frog jumps 5 to the right, 2 to the left and 5 to the right so the answer is 5−2+5=8.
In the second query frog jumps 100 to the right, 1 to the left, 100 to the right and 1 to the left so the answer is 100−1+100−1=198.
In the third query the answer is 1−10+1−10+1=−17.
In the fourth query the answer is 109−1+109−1+109−1=2999999997.
In the fifth query all frog's jumps are neutralized by each other so the answer is 0.
The sixth query is the same as the fifth but without the last jump so the answer is 1.
第一次查询中,青蛙向右跳 5,向左跳 2,再向右跳 5,因此答案为 5−2+5=8。
第二次查询中,青蛙向右跳 100,向左跳 1,向右跳 100,再向左跳 1,因此答案为 100−1+100−1=198。
第三次查询中,答案为 1−10+1−10+1=−17。
第四次查询中,答案为 109−1+109−1+109−1=2999999997。
第五次查询中,青蛙的所有跳跃相互抵消,因此答案为 0。
第六次查询与第五次相同,但缺少最后一次跳跃,因此答案为 1。
输入解题思路,AI测评打分。不知道怎么写?