CF1077A.Frog Jumping

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A frog is currently at the point 00 on a coordinate axis OxOx. It jumps by the following algorithm: the first jump is aa units to the right, the second jump is bb units to the left, the third jump is aa units to the right, the fourth jump is bb 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 xx to position x+ax+a;
  • otherwise it jumps from its current position xx to position x−bx-b.

Your task is to calculate the position of the frog after kk jumps.

But... One more thing. You are watching tt different frogs so you have to answer tt independent queries.

一只青蛙当前位于坐标轴 OxOx 上的点 00 处。它按照以下规则跳跃:第一次向右跳 aa 个单位,第二次向左跳 bb 个单位,第三次向右跳 aa 个单位,第四次向左跳 bb 个单位,依此类推。

形式化地定义如下:

  • 若青蛙在当前跳跃之前已跳跃偶数次,则它从当前位置 xx 跳至位置 x+ax+a;
  • 否则,它从当前位置 xx 跳至位置 x−bx-b。

你的任务是计算青蛙经过 kk 次跳跃后的位置。

但是……还有一点:你正在同时观察 tt 只不同的青蛙,因此你需要回答 tt 个相互独立的查询。

输入格式

The first line of the input contains one integer tt (1≤t≤10001 \le t \le 1000) — the number of queries.

Each of the next tt lines contain queries (one query per line).

The query is described as three space-separated integers a,b,ka, b, k (1≤a,b,k≤1091 \le a, b, k \le 10^9) — the lengths of two types of jumps and the number of jumps, respectively.

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示查询次数。

接下来的 tt 行每行包含一个查询(每行一个查询)。

每个查询由三个以空格分隔的整数 a,b,ka, b, k(1≤a,b,k≤1091 \le a, b, k \le 10^9)描述,分别表示两种跳跃的长度以及跳跃总次数。

输出格式

Print tt integers. The ii-th integer should be the answer for the ii-th query.

输出 tt 个整数。其中第 ii 个整数应为第 ii 个查询的答案。

输入输出样例

  • 输入#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 55 to the right, 22 to the left and 55 to the right so the answer is 5−2+5=85 - 2 + 5 = 8.

In the second query frog jumps 100100 to the right, 11 to the left, 100100 to the right and 11 to the left so the answer is 100−1+100−1=198100 - 1 + 100 - 1 = 198.

In the third query the answer is 1−10+1−10+1=−171 - 10 + 1 - 10 + 1 = -17.

In the fourth query the answer is 109−1+109−1+109−1=299999999710^9 - 1 + 10^9 - 1 + 10^9 - 1 = 2999999997.

In the fifth query all frog's jumps are neutralized by each other so the answer is 00.

The sixth query is the same as the fifth but without the last jump so the answer is 11.

第一次查询中,青蛙向右跳 55,向左跳 22,再向右跳 55,因此答案为 5−2+5=85 - 2 + 5 = 8。

第二次查询中,青蛙向右跳 100100,向左跳 11,向右跳 100100,再向左跳 11,因此答案为 100−1+100−1=198100 - 1 + 100 - 1 = 198。

第三次查询中,答案为 1−10+1−10+1=−171 - 10 + 1 - 10 + 1 = -17。

第四次查询中,答案为 109−1+109−1+109−1=299999999710^9 - 1 + 10^9 - 1 + 10^9 - 1 = 2999999997。

第五次查询中,青蛙的所有跳跃相互抵消,因此答案为 00。

第六次查询与第五次相同,但缺少最后一次跳跃,因此答案为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页