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;
}
题意:
给你一个数组,你可以把数组分为任意连续的部分,让这些部分的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;
}
给你一个数组,假设一个数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;
}
给你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;
}