Codeforces Round #814 (Div. 2)(A B C)题解

A题

Problem - A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1719/problem/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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dawpro_加薪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值