Codeforces Round #752 (Div. 2)

A. Era

贪心水题 从第一个位置开始加1一直到所有数都满足 ai<=i 我们可以找到最大的 ai-i 遍历一下就能找到 在他的前面加 ai-i个1就可以满足题意了

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a[110];
ll amax;
ll pos;

void solve()
{
	int n;
	cin >> n;
	amax = -1; pos = -1;
	for (int i = 1; i <= n; i ++ ) 
	{
		cin >> a[i];
		amax = max(a[i] - i, amax);
	}
	cout << amax << endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	while (t -- )
	{
		solve();
	} 


	return 0;
}

B. XOR Specia-LIS-t

题意 : 给定一个正整数序列 要求将其分为k个子序列 将第i个子序列中的上升子序列最大长度设为 hi 最后可以得出 [h1, h2, h3 … hk] 问是否可以通过分子序列把h1到hk的异或和变为0
如果n是偶数的话 我们可以分成偶数个只包括一个元素的子序列 最后异或和肯定为0 如果是奇数的话 我们可以去找是否存在两个元素 即ai > ai+1 如果存在则可以将其看成一个子序列 因为他的h值依然为1 如果都不行则输出NO

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

ll a[N];
int n;

void solve()
{
	cin >> n;
	bool flag = false;
	for (int i = 1; i <= n; i ++ ) 
	{
		cin >> a[i];
		if (a[i] <= a[i - 1]) flag = true; 
	}
	if (n % 2 == 0) puts("YES");
	else if ((n & 1) && flag) puts("YES");
	else puts("NO");
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	while (t -- )
	{
		solve();
	} 


	return 0;
}

C - Di-visible Confusion

从头到尾暴力即可 每个数都看看从2到当前位置是否可以被除 如果不可以则break 因为遍历的数字如果都可以被x整除则说明这些数都是x的因子 x又不会很大 所以暴力能行

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

ll n;
ll a[N], pos;

void solve()
{
	cin >> n; pos = 2;
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	for (int i = 1; i <= n; i ++ )
	{
		bool flag = false;
		for (int j = 2; j <= pos; j ++ )
			if (a[i] % j != 0) {pos ++ ; flag = true; break;}
		if (!flag) {puts("NO"); return;}
	}
	puts("YES");
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	while (t -- )
	{
		solve();
	} 


	return 0;
}

D - Moderate Modular Mode

给定一个 x 一个 y 求 n 使得 n % x = y % n
分类讨论 当 x > y 的时候 我们只要让 n 比 x 多于 y 即可
当 x <= y 的时候 n 肯定是在 x, y 中间的 我们让y比n多一小块c 然后n=kx + c 求c看一下这个图
在这里插入图片描述
c = (y % x) / 2 求c即可

代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;

void solve()
{
	ll a, b;
	cin >> a >> b;
	if (a > b) cout << (ll)a + b << endl;
	else 
	{
		ll l = (b % a) / 2;
		b -= l; cout << b << endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;
	while (t -- )
	{
		solve();
	} 


	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值