2021-11-01

Codeforces Round #752 (Div. 2)

A. Era
题意:

给你个数组,你可以在数组的任何一个位置插入一个数,问你要操作几次,才能使数组的所有下标(从1开始)都大于等于a[i]

做法:

只要求出初始数组中每个数减去所在下标的最大值就行。

代码:

// Problem: F. Artistic Partition
// Contest: Codeforces - Codeforces Round #752 (Div. 2)
// URL: https://codeforces.com/contest/1604/problem/F
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

int n;
int a[110];

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

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

B.XOR Specia-LIS-t

题意:

给你一个数组,你可以把数组分为任意连续的部分,让这些部分的LIS的异或值为0,问你是否能分。

做法:

1异或1为0,我们可以分为n部分,每一部分都只有一个数,每次两两异或就是0,所以当数组长度为偶数的时候成立。当数组长度为奇数的时候,看看能不能找到前一个大于等于后一个的,如果有我们可以把他们放在一组,这样部分的LIS仍然是1,这样就又可以分为偶数个异或值为0的部分,若找不到,就是不能分。

代码:

// Problem: B. XOR Specia-LIS-t
// Contest: Codeforces - Codeforces Round #752 (Div. 2)
// URL: https://codeforces.com/contest/1604/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

int n;
int a[100010];
void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i ++ ) cin >> a[i];
    if(n % 2 == 0){
    	cout << "YES" << endl;
    	return;
    }
    bool flag;
    for(int i = 1; i + 1 <= n; i ++ ){
    	if(a[i] >= a[i + 1]){
    		cout << "YES" << endl;
    		return;
     	}
    }
    cout << "no" << endl;
}

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

C. Di-visible Confusion
题意:

给你一个数组,假设一个数x的当前下标为i,你可以让它消失,当且仅当x % (i + 1) !=0,问你是否能把数组清空。

做法:

本题要发现:如果在2 ~ i+1 中,存在不能整除a[i] 的数,那么a[i]一定能被清除,相反,如果在2 ~ i + 1中都能整除a[i] 那么就不能清空,这种情况就是满足lcm(2,3 …i + 1)能整除a[i]
所以我们这题只要对每个a[i]判断他是否能被清除就行。枚举的时候不用把所有的枚举到n,因为lcm(1, 2, …23)已经超过1e9,所以只需要枚举到min(i + 1, 23).

// Problem: C. Di-visible Confusion
// Contest: Codeforces - Codeforces Round #752 (Div. 2)
// URL: https://codeforces.com/contest/1604/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return (a / gcd(a, b)) * b;}

int n;
int a[100010];

void solve()
{
	cin >> n;
	for(int i = 1; i <= n; i ++ ) cin >> a[i];
	for(int i = 1; i <= n; i ++ )
	{
		int x = 1;
		for(int j = 2; j <= min(i + 1, 23); j ++ )
		{
			x = lcm(j, x);
		}
		if(a[i] % x == 0){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
	return;
}


int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}

D. Moderate Modular Mode
题意:

给你x, y. 问你能不能找到一个n,满足n % x = y % x。其中1 <=x,y <= 1e9,
1<=n<=1e18

做法:
本题分情况讨论x和y的大小关系

若x = y, n = x,等式左右两边都是0;
若x > y, n = x + y, 等式左右两边都是y。
若x < y, 时,我们可以把问题想象成一个数轴,从0开始以x单位移动,移动至下一次移动超过或刚好到y,我们记这一点为p,然后我们要找的n就是py的中点
在这里插入图片描述

// Problem: D. Moderate Modular Mode
// Contest: Codeforces - Codeforces Round #752 (Div. 2)
// URL: https://codeforces.com/contest/1604/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define debug cout << "!!!!!!!!" << endl;
#define pb push_back
#define fi first
#define se second
#define PII pair<int,int>
#define me(a,x) memset(a, x, sizeof(a))
typedef long long LL;

using namespace std;

LL x, y;
LL n;

void solve()
{
	cin >> x >> y;
	if(x == y){
		n = x;
	}else if(x > y){
		n = x + y;
	}else if(x < y){
		LL shang;
		if(!(y % x)) shang = y / x - 1;
		else shang = y / x;
 		n = shang * x + (y - shang * x) / 2;
	}
	cout << n << endl;	
}

int main()
{
    int T = 1;
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> T;
    while(T -- )
    {
        solve();
    }
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值