A.Chip Game

题目描述

Burenka and Tonya are playing an old Buryat game with a chip on a board of n \times m cells.

At the beginning of the game, the chip is located in the lower left corner of the board. In one move, the player can move the chip to the right or up by any odd number of cells (but you cannot move the chip both to the right and up in one move). The one who cannot make a move loses.

Burenka makes the first move, the players take turns. Burenka really wants to win the game, but she is too lazy to come up with a strategy, so you are invited to solve the difficult task of finding it. Name the winner of the game (it is believed that Burenka and Tonya are masters of playing with chips, so they always move in the optimal way).

Chip’s starting cell is green, the only cell from which chip can’t move is red. if the chip is in the yellow cell, then blue cells are all options to move the chip in one move.

输入格式

The first line contains one integer t ( 1 ≤q t ≤q 10^4 ) — the number of test cases. The following is a description of the input data sets.

The only line of each test case contains two integers n and m ( 1 ≤q n, m ≤q 10^9 ) — the dimensions of the game board.

输出格式

For each test case print a single line — the name of the winner of the game (“Burenka” or “Tonya”).

样例 #1

样例输入 #1

6
1 1
1 4
5 6
2 2
6 3
999999999 1000000000

样例输出 #1

Tonya
Burenka
Burenka
Tonya
Burenka
Burenka

提示

In the first case, Burenka has no move, so Tonya wins.

In the second case, Burenka can move 3 cells to the right, after which Tony will not be able to make a move, which means that Burenka wins.

In the third case, Burenka can move 5 squares to the right. Then we can say that we have a game on a board of 1 \times 5 cells, and Tonya is the first player. In such game the second player wins, so in the original one Burenka will win.

思路

贪心,如果m+n为奇数时,Burenka总会赢,反之,Tonya会赢。

  • 证明:对于这两个玩家来说,只能向右或者向上走,因此他们每次走的步数总为m+n,并且每次只能走奇数步,所以如果m+n为奇数时burenka会赢,反之,Tonya会赢

另外:记得开Long long

C++代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>using namespace std;typedef long long ll;void solve()
{ll a , b;cin >> a >> b;if( (a+b) % 2 == 0)puts("Tonya");elseputs("Burenka");}int main()
{int T;cin >> T;while(T --)solve();return 0;
}

B.Mathematical Circus

题面翻译【转洛谷】

给你两个整数 n,kn为偶数),让你将 1nn个数分成 \dfrac{n}{2}个有序二元组 (a,b),满足 (a+k)\cdot b能被 4整除。可能不存在合法解。

输入第一行一个整数 t(1≤ t≤ 10^4),表示有 t组数据。接下来 t行每行两个整数 n,k(2≤ n≤2\times10^5,0≤ k≤10^9,n为偶数 ),含义如题面所述。保证 \sum n≤2\times10^5

对于每一组数据,首先输出一行一个字符串“YES”或“NO”,表示对于给定 n,k是否存在合法解。如果存在合法解,接下来 \dfrac{n}{2}行输出你构造的合法解,每行两个整数 a,b

题目描述

A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — n and k , where n is even. Next, he takes all the integers from 1 to n , and splits them all into pairs (a, b) (each integer must be in exactly one pair) so that for each pair the integer (a + k) \cdot b is divisible by 4 (note that the order of the numbers in the pair matters), or reports that, unfortunately for viewers, such a split is impossible.

Burenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers n and k .

Tonya is a wolf, and as you know, wolves do not perform in the circus, even in a mathematical one. Therefore, he asks you to help him. Let him know if a suitable splitting into pairs is possible, and if possible, then tell it.

输入格式

The first line contains one integer t ( 1 ≤q t ≤q 10^4 ) — the number of test cases. The following is a description of the input data sets.

The single line of each test case contains two integers n and k ( 2 ≤q n ≤q 2 \cdot 10^5 , 0 ≤q k ≤q 10^9 , n is even) — the number of integers and the number being added k .

It is guaranteed that the sum of n over all test cases does not exceed 2 \cdot 10^5 .

输出格式

For each test case, first output the string “YES” if there is a split into pairs, and “NO” if there is none.

If there is a split, then in the following \frac{n}{2} lines output pairs of the split, in each line print 2 numbers — first the integer a , then the integer b .

样例 #1

样例输入 #1

4
4 1
2 0
12 10
14 11

样例输出 #1

YES
1 2
3 4
NO
YES
3 4
7 8
11 12
2 1
6 5
10 9
YES
1 2
3 4
5 6
7 8
9 10
11 12
13 14

提示

In the first test case, splitting into pairs (1, 2) and (3, 4) is suitable, same as splitting into (1, 4) and (3, 2) .

In the second test case, (1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2 is not divisible by 4 , so there is no partition.

思路

对于k来说:

  • 如果k是奇数:总会有合适方案。(奇数+奇数)* 偶数一定是偶数
  • 如果k是偶数:
    1. k是4的倍数,找不到合适的方案
    2. k%4 == 2,合适的方案:所有4的倍数作为b,与相应的奇数匹配;剩下的偶数作为a,与奇数配对

C++代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>using namespace std;void solve()
{int n , k;cin >> n >> k;if( k % 2 == 1){puts("YES");for(int i = 1;i < n;i += 2)cout << i << " " << i + 1 << endl;}else{if(k % 4 == 0)puts("NO");else{puts("YES");bool flag = false;for(int i = 1;i <= n;i += 2){if(flag == false)cout << i + 1 << " " << i << endl;elsecout << i << " " << i + 1 << endl;flag = !flag;}}}}int main()
{int T;cin >> T;while(T --)   solve();return 0;
}

C.Fighting Tournament

题面翻译【转洛谷】

题意

Burenka正准备去观看一年中最有趣的体育活动 —— 她朋友Tonya组织的格斗锦标赛。

n 名运动员参加了大赛,标号分别为为 1,2,… ,n 。第 i 名运动员的实力是 a_i(1 ≤ a_i ≤ n)每个运动员的实力是不同的,也就是说,数组 a 是 n 的 一种 全排列

大赛的流程是这样的:

一开始,运动员们按标号从小到大排成一列,队头为 1 号运动员,队尾为 n 号运动员。

每轮一次比赛,队头的两个人进行格斗,赢的人(实力较强的人)变成队头,输的人变成队尾

Burenka 问了 Tonya q 个问题,每个问题包含两个整数 ik ,表示 i 号运动员在前 k 轮中会胜多少场

输入格式

第一行一个整数 t (1≤ t≤ 10^4),表示数据组数。

对于每组数据:

第一行两个整数 nq (2≤ n ≤ 10^5,1≤ q≤ 10^5),表示 参加大赛的运动员数量 和 问题数量。

第二行 n 个整数 a_1,a_2,...,a_n(1≤ a_i≤ n),表示数组 a,而且是个 全排列

接下来的 q 行表示每个问题,每行两个整数 ik (1≤ i≤ n,1≤ k≤ 10^9),表示运动员的标号轮数

输出格式

对于每个问题,一行一个整数表示 问题的答案

题目描述

Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya.

n athletes participate in the tournament, numbered from 1 to n . Burenka determined the strength of the i -th athlete as an integer a_i , where 1 ≤q a_i ≤q n . All the strength values are different, that is, the array a is a permutation of length n . We know that in a fight, if a_i > a_j , then the i -th participant always wins the j -th.

The tournament goes like this: initially, all n athletes line up in ascending order of their ids, and then there are infinitely many fighting rounds. In each round there is exactly one fight: the first two people in line come out and fight. The winner goes back to the front of the line, and the loser goes to the back.

Burenka decided to ask Tonya q questions. In each question, Burenka asks how many victories the i -th participant gets in the first k rounds of the competition for some given numbers i and k . Tonya is not very good at analytics, so he asks you to help him answer all the questions.

输入格式

The first line contains one integer t ( 1 ≤q t ≤q 10^4 ) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers n and q ( 2 ≤q n ≤q 10^5 , 1 ≤q q ≤q 10^5 ) — the number of tournament participants and the number of questions.

The second line of each test case contains n integers a_1, a_2, \ldots, a_n ( 1 ≤q a_i ≤q n ) — the array a , which is a permutation.

The next q lines of a test case contain questions. Each line contains two integers i and k ( 1 ≤q i ≤q n , 1 ≤q k ≤q 10^9 ) — the number of the participant and the number of rounds.

It is guaranteed that the sum of n and the sum of q over all test cases do not exceed 10^5 .

输出格式

For each Burenka’s question, print a single line containing one integer — the answer to the question.

样例 #1

样例输入 #1

3
3 1
3 1 2
1 2
4 2
1 3 4 2
4 5
3 2
5 2
1 2 3 5 4
5 1000000000
4 6

样例输出 #1

2
0
1
0
4

提示

In the first test case, the first numbered athlete has the strength of 3 , in the first round he will defeat the athlete with the number 2 and the strength of 1 , and in the second round, the athlete with the number 3 and the strength of 2 .

In the second test case, we list the strengths of the athletes fighting in the first 5 fights: 1 and 3 , 3 and 4 , 4 and 2 , 4 and 1 , 4 and 3 . The participant with the number 4 in the first 5 rounds won 0 times (his strength is 2 ). The participant with the number 3 has a strength of 4 and won 1 time in the first two fights by fighting 1 time.

思路

来自:你好_Ä
我们可以知道,如果某个人的能量值是n的时候,没有人会赢他,那么我们可以先找到能量最大的人,并记为king,只要是出现在king后边的人,就没有赢的机会

记录下每个选手第一次获胜的场次和最后一次获胜的场次(初始化都为0)

对于每次询问,有多种情况:

  • 赢的次数为0的情况:

    1. 当前选手在king后面
    2. k小于选手第一次赢得场次
    3. 选手第一次赢得场次为0
  • 赢的次数为最后一次赢的场次 - 第一次赢的场次 + 1
    1. k大于选手最后一次赢得的场次
  • 赢的次数为k - 第一次赢的场次 + 1
    1. 这个选手是king
    2. k小于这个选手最后一次赢的场次

C++代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>using namespace std;typedef long long ll;
typedef pair<ll,ll> PII;void solve()
{ll n , q;cin >> n >> q;vector <ll> a(n+1);ll king;for(ll i = 1;i <= n;i ++){cin >> a[i];if(a[i] == n)    king = i;}vector<PII> b(n+1);//������ŵ�һ�λ�ʤ�ij��������һ�λ�ʤ�ij���ll x = a[1];ll pos = 1,cnt = 1;for(ll i = 2;i <= n;i ++){if(a[i] < x){if(b[pos].second == 0)b[pos].first = cnt;b[pos].second = cnt;}else{x = a[i];pos = i;b[pos].first = cnt;b[pos].second = cnt;}cnt ++;}while(q --){ll i , k;cin >> i >> k;if(i > king || i > k + 1 || b[i].first > k || b[i].first == 0)cout << 0 << endl;else if(i == king)cout << k - b[i].first + 1 << endl;else{if(k >= b[i].second)cout << b[i].second - b[i].first + 1 << endl;elsecout << k - b[i].first + 1 << endl;}}
}int main()
{int T;cin >> T;while(T --)   solve();return 0;
}

Codeforces Round #814 (Div. 2)相关推荐

  1. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  2. 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 ...

  3. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  4. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  5. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  6. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  7. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  8. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  9. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

最新文章

  1. 图解Istio原理和实践--云平台技术栈18
  2. R 回归 虚拟变量na_工具amp;方法 | R语言机器学习包大全(共45个包)
  3. 使用Exiv2读取图像属性的详细信息
  4. 【客户下单】基于CRM完全匹配地址库实现自动分单
  5. ipguard客户端如何卸载_客户端navicat遇到问题怎么办?
  6. MongoDB 设置权限认证
  7. 前端学习(501):水平居中布局得第二种方式的优缺点
  8. 常用m脚本控制simulink模块方法
  9. 微信点餐系统技术总结
  10. Java【付诸实践 04】Jar包class文件反编译、修改、重新编译打包方法(含反编译工具jd-gui-windows-1.6.6.zip百度云资源)
  11. fcm算法的MATLAB实现
  12. 一个div分上下两部分,上部分高度不固定,下面部分自动填满剩余高度
  13. 【NOIP2014】飞扬的小鸟
  14. 判断设置了css省略号样式的元素是否出现了省略号
  15. 2012多校联盟第二场1009 还是BFS
  16. 农林学科英语 课后习题答案与复习大纲
  17. 基于MaxScale中间件的MySQL读写分离
  18. 使用YOLOv3训练BDD100K数据集之标签格式转换
  19. 关于微信HOOK协议,包括云控的后续开发经验
  20. 【一起读论文系列1】基于压缩感知的语音编解码方向研究

热门文章

  1. Java学习到大神级别流程——转发自黑马程序员
  2. 文字转语音百度 android视频教程,【案例】免费文字转语音:运用百度语音合成智能朗读...
  3. PHP实现小程序微信支付(v3版本)
  4. 【长难句分析精讲】从属复合句
  5. 各种开源协议License明细
  6. 欧拉工程第六题 平方和与和平方的差是多少
  7. [日推荐]『传图识字』让人工智能帮你识别照片里的文字!
  8. HTML+CSS大作业: 美食网页制作作业_生猛海鲜美食网页设计
  9. c语言设计随机矩阵,C语言如何生成一个随机矩阵
  10. 清华北大 全球大学排名