题目翻译:

The grasshopper(蚂蚱) is located on the numeric axis (数轴)at the point with coordinate(坐标) x0.

一个蚱蜢在数轴上,初始坐标为x0

Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinate x with a distance d to the left moves the grasshopper to a point with a coordinate x−d, while jumping to the right moves him to a point with a coordinate x+d.

The grasshopper is very fond of positive integers(正整数), so for each integer i starting with 1 the following holds: exactly iiminutes after the start he makes a jump with a distance of exactly i. So, in the first minutes he jumps by 1, then by 2, and so on.

开始后一分钟移动距离为1,两分钟移动距离为2,.....,

The direction of a jump is determined as follows: if the point where the grasshopper was before the jump has an even(偶数的) coordinate, the grasshopper jumps to the left, otherwise he jumps to the right.

移动方向由以下规则决定:

如果坐标是偶数,向左移

如果坐标是奇数,向右移

For example, if after 18 consecutive jumps he arrives at the point with a coordinate 77, he will jump by a distance of 19 to the right, since 77 is an odd number, and will end up at a point 7+19=267+19=26. Since 26 is an even number, the next jump the grasshopper will make to the left by a distance of 20, and it will move him to the point 26−20=626−20=6.

Find exactly which point the grasshopper will be at after exactly n jumps.

问题:求跳n次后,蚱蜢的坐标

Input

The first line of input contains an integer tt(1≤t≤10^4) — the number of test cases.

Each of the following tt lines contains two integers x0

and n  — the coordinate of the grasshopper's initial position and the number of jumps.

输入:

第一行输入case个数

以下各行输入两个数,第一个数是起始坐标,第二个数是跳n次后的坐标

Output

Print exactly tt lines. On the ii-th line print one integer — the answer to the ii-th test case — the coordinate of the point the grasshopper will be at after making nn jumps from the point x0.

输出:

每一行表示每一个case jump 结束后的坐标

完整问题:

一个蚱蜢在数轴上,初始坐标为x0,开始后一分钟移动距离为1,两分钟移动距离为2,.....,

移动方向由以下规则决定:  如果坐标是偶数,向左移  如果坐标是奇数,向右移

问题:求跳n次后,蚱蜢的坐标

输入:

第一行输入case个数

以下各行输入两个数,第一个数是起始坐标,第二个数是跳n次后的坐标

输出:

每一行表示每一个case jump 结束后的坐标

思路:

奇数+奇数=偶数

奇数+偶数=奇数

偶数+偶数=偶数

一步步写可以看出规律

4个一组和为0,xo分奇偶讨论,n分模4讨论

代码:

#include<iostream>
#include<vector>using namespace std;long long jump(long long x, long long n)
{if (x % 2 != 0){if (n % 4 == 0){return x;}else if (n % 4 == 1){return x + n;}else if (n % 4 == 2){return x - 1;}else if (n % 4 == 3){return x - n - 1;}}else{if (n % 4 == 0){return x;}else if (n % 4 == 1){return x - n;}else if (n % 4 == 2){return x + 1;}else if (n % 4 == 3){return x + n + 1;}}
}
int main()
{long long m;cin >> m;vector<vector< long long>>input;vector< long long>temp;long long x1, n1;while (m--){cin >> x1;cin >> n1;temp.push_back(x1);temp.push_back(n1);input.push_back(temp);temp.clear();}for (int i = 0; i < input.size(); i++){x1 = input[i][0];n1 = input[i][1];cout << jump(x1, n1) << endl;}
}

CodeForces round 753 problem B Odd Grasshopper(奇怪的蚱蜢)相关推荐

  1. CodeForces round 753 problem A Linear Keyboard(线性键盘)

    问题翻译: You are given a keyboard that consists of 26 keys. The keys are arranged sequentially(按顺序) in ...

  2. Codeforces Round #753 (Div. 3) A-E

    打的烂的一批. 目录 A. Linear Keyboard[简单 /模拟] B. Odd Grasshopper[简单 / 找规律] C. Minimum Extraction[一般 / 排序 思维] ...

  3. Educational Codeforces Round 16 C. Magic Odd Square 矩阵构造

    传送门 文章目录 题意: 思路: 题意: 给你一个奇数nnn,让你构造一个n∗nn*nn∗n的矩阵,矩阵的每个位置依次填上[1,n∗n]之内的数[1,n*n]之内的数[1,n∗n]之内的数,满足每行. ...

  4. Codeforces Round #753 (Div. 3)E. Robot on the Board 1

    问题翻译: The robot is located on a checkered rectangular(直角 的) board of size n×m (n rows, m columns). T ...

  5. Codeforces Round #753 (Div. 3) C. Minimum Extraction(最小抽离)

    题目翻译: Yelisey has an array a of n integers. 数组a中有n个整数 If a has length strictly greater than 1, then ...

  6. Educational Codeforces Round 32

    http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...

  7. Codeforces Round #628 (Div. 2) E. Ehab‘s REAL Number Theory Problem 巧妙的质因子建图

    传送门 文章目录 题意: 思路: 题意: 给你nnn个数,每个数的因子个数不超过777个,选出最少的数使其乘积为平方数. n≤1e5n\le 1e5n≤1e5 思路: 由于因子不超过777个,所以由约 ...

  8. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. 微信小程序----日期时间选择器(自定义精确到分秒或时段)
  2. POJ - 1185 炮兵阵地(状压dp)
  3. 二分法查找和普通查找
  4. C语言运算符的优先级及结合性
  5. 管家婆打印自定义编辑_打印相关,人手一份!
  6. Grep 用法和正则表达式(一)
  7. 清华谭浩强编著的c语言程序设计教程,清华大学谭浩强C语言程序设计教程第3版 (9).doc...
  8. 第一章:状态化流处理概述
  9. vcm驱动芯片原理_手机Cam和era模组及VCM与VCMDriver介绍.pptx
  10. 植物大战僵尸:实现灵魂收割者
  11. 解决ROS工作空间每次使用都要source的问题
  12. 每日一问 --什么是正弦信号?正弦信号有哪些特性?
  13. 很常用的倒计时脚本,可任意设置时…
  14. card样式 layui_layui后台模板
  15. “独立站+私域”的DTC直客模式电商,是告别互联网内卷唯一有效方式
  16. 第一篇博客------自我介绍
  17. 小呀嘛小二郎 背着那书包上学堂
  18. java写文件用二进制分割_java分割二进制文件
  19. 前端布局 Flex(弹性)布局
  20. 微软笔记本怎么装linux,微软正在为XO笔记本装Win/Linux双系统

热门文章

  1. UVA11565 Simple Equations【数学+暴力】
  2. Vijos P1335 数独验证【谜题】
  3. CCF201403-4 无线网络(100分)
  4. HDU2102 A计划【BFS】
  5. 计算最大子段(分治法)
  6. 常见空指针异常及其避免
  7. linux 命令学习 —— 硬件外设管理(dmesg、lsusb)
  8. 使用 matlab 数字图像处理(七)—— 频率域处理
  9. Tricks(三十五)—— 内积的极简实现
  10. Python基础——numpy.ndarray一维数组与多维数组