Codeforces Round #814 (Div. 2)
作者:互联网
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");
else
puts("Burenka");
}
int main()
{
int T;
cin >> T;
while(T --)
solve();
return 0;
}
B.Mathematical Circus
题面翻译【转洛谷】
给你两个整数 n,k
(n
为偶数),让你将 1
到 n
这 n
个数分成 \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是偶数:
- k是4的倍数,找不到合适的方案
- 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;
else
cout << 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 个问题,每个问题包含两个整数 i 和 k ,表示 i 号运动员在前 k 轮中会胜多少场。
输入格式
第一行一个整数 t (1≤ t≤ 10^4)
,表示数据组数。
对于每组数据:
第一行两个整数 n 和 q (2≤ n ≤ 10^5,1≤ q≤ 10^5)
,表示 参加大赛的运动员数量 和 问题数量。
第二行 n 个整数 a_1,a_2,...,a_n(1≤ a_i≤ n)
,表示数组 a,而且是个 全排列。
接下来的 q 行表示每个问题,每行两个整数 i 和 k (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
的情况:- 当前选手在king后面
- k小于选手第一次赢得场次
- 选手第一次赢得场次为0
- 赢的次数为
最后一次赢的场次 - 第一次赢的场次 + 1
- k大于选手最后一次赢得的场次
- 赢的次数为
k - 第一次赢的场次 + 1
- 这个选手是king
- 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;
else
cout << k - b[i].first + 1 << endl;
}
}
}
int main()
{
int T;
cin >> T;
while(T --) solve();
return 0;
}
标签:Burenka,10,Codeforces,Tonya,test,Div,include,814,first 来源: https://www.cnblogs.com/heystar/p/16593813.html