A题
本题是一个游戏,两人轮流走,只能向右或者向上走奇数步,我们想帮Burenka找出是否有必赢方案。也就是使得Tonya 无路可走。
思路:
我们可以通过几个样例分析出如果所给矩形的长宽奇偶性不同,那么Burenka必赢,否则另一个人必赢。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int t;
signed main()
{
cin >> t;
int n, m;
while (t--)
{
scanf("%d%d", &n, &m);
if (n % 2 == m % 2) puts("Tonya");
else puts("Burenka");
}
return 0;
}
B题
Problem - B - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1719/problem/B题意:
从1 - n 中, 要求分割成 n / 2 对数, 使得例如某一对为a, b, 那么 (a + k) * b % 4 == 0.
思路:
我们直接从1 - n遍历, 每次加2, 如果 (i + k) * (i + 1) 符合,就输出i 和 i + 1, 如果反之成立,就输出 i + 1 和 i, 如果都不成立则输出NO.
代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std;
const int N = 200010;
int T;
bool rser[N];
signed main()
{
cin >> T;
while (T--)
{
int n, k;
scanf("%d%d", &n, &k);
bool is = false;
memset(rser, false, sizeof rser);
for (int i = 1; i <= n; i += 2)
{
if ((i + k) % 4 != 0 && (i + k) * (i + 1) % 4 != 0)
{
if ((i + 1 + k) % 4 == 0 || (i + 1 + k) * i % 4 == 0) rser[i] = true;
else {
is = true;
break;
}
}
}
if (is) puts("NO");
else {
puts("YES");
for (int i = 1; i <= n; i += 2) {
if(!rser[i]) printf("%d %d\n", i, i + 1);
else printf("%d %d\n", i + 1, i);
}
}
}
return 0;
}
C题
Problem - C - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1719/problem/C题意:
n个选手比赛, 每个选手的强壮度都不一样,越强壮的赢,从1 开始往后比赛, 如果输了到最后,赢了继续往下比赛,处理q个询问, 每个询问问第i个人在前k回合的胜场。
思路:
我们可以知道,如果i大于强壮度最大选手, 那么它一定不会有胜利场次,输出0;
如果 i 是强壮度最大选手,那么它的场次就是k - i + 2;
如果 i 是强壮度之前的选手,我们通过预处理的胜利场次和k处理即可得到答案。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int T;
int a[N];
int s[N];
signed main()
{
cin >> T;
while (T--)
{
int n, q;
scanf("%lld%lld", &n, &q);
memset(s, 0, sizeof s);
int ma = 0, mai = -1;
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
if (ma < a[i]) ma = a[i], mai = i;
}
for (int i = 1; i <= mai; ) {
int x = i + 1;
while (a[i] > a[x] && x <= mai) ++s[i], ++ x;
if(x <= mai) s[x] ++;
i = x;
}
while (q--)
{
int i, k;
scanf("%lld%lld", &i, &k);
if (i > mai || k < i - 1) {
printf("%d\n", 0);
}
else {
int c = max((int)1, i - 1);
if (i < mai) {
if(k - c >= s[i])printf("%lld\n", s[i]);
else if(k == c) printf("%lld\n", 1);
else printf("%lld\n", k - c + 1);
}
else {
if (k >= c) printf("%lld\n", k + 1 - c);
}
}
}
}
return 0;
}