Codeforces Round #752
A - Era
题意
给一个数组a 不断在任意在一个位置插入任意一个元素 问最少执行多少次插入使得每个ai都小于等于i
思路
在最前面不断插入1 找ai-i的最大值 即要插入1的个数
代码
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll t,n,te;
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
cin>>n;
ll ans=0;
for(int i=1;i<=n;i++)
{
cin>>te;
ans=max(ans,te-i);
}
cout<<ans<<endl;
}
return 0;
}
B - XOR Specia-LIS-t
题意
给一个长度为n数组 将它分成任意段 每段代表的值为这段数组最大上升子序列的最大长度 问是否能通过分段达成每段代表的值最后异或为0
思路
如果n%2==0这样每个数都分一段 这样就有偶数个1异或 结果为0
如果n为奇数 寻找数组中是否存在a[i]<=a[i-1] 如果存在 就把这两个分成一组 其代表的值为1 这样总共还是偶数个1
代码
#include<iostream>
#include<algorithm>
#define N 100005
using namespace std;
typedef long long ll;
ll t,n,te,a[N];
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
cin>>n;
if(n%2==0)
{
for(int i=1;i<=n;i++)
cin>>te;
cout<<"YES\n";
continue;
}
int flag=0;
cin>>a[1];
for(int i=2; i<=n; i++)
{
cin>>a[i];
if(flag==0&&a[i]<=a[i-1])
flag=1;
}
if(flag)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
C - Di-visible Confusion
题意
每次可以选择数组中的第 i 个元素a[i],若其不能被i+1整除,则可以删除它。
求是否可以将数组清空。
思路
暴力找a[i]是否能被2-到i+1的数整除
优化 一个数必不能被他的因子-1 整除 1-30的最小公倍数已经超过longlong 所有查找前30是否是a[i]的不能整除的数就行
代码
#include<iostream>
#include<algorithm>
#define N 100005
using namespace std;
typedef long long ll;
ll t,n,te,a[N];
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
cin>>n;
int flag2=1;
for(int i=1; i<=n; i++)
{
cin>>a[i];
int flag=1;
if(flag2)
for(int j=2; j<=min(30,i+1); j++)
{
if(a[i]%j!=0)
{
flag=0;
break;
}
}
if(flag)
flag2=0;
}
if(flag2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
D - Moderate Modular Mode
题意
对于偶数x,y 找到一个n 使得n%x=y%n
思路
1.当y%x==0 n=x||y即可
2.当x>y n=x+y即可
3.当x<y 如果n<=x n%x=n 而y%n必然< n 不成立
如果n>y n%x<x y%n=y>x 不成立
所以x<n<y
要求t相等且t必<x 将1式变形带入2式
k2取最小 k1取最大
代码
#include<iostream>
#include<algorithm>
#define N 100005
using namespace std;
typedef long long ll;
ll t,n,te,x,y;
int main()
{
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
cin>>x>>y;
if(y%x==0)
cout<<x<<"\n";
else if(x>y)
cout<<x+y<<"\n";
else
{
cout<<(y+y/x*x)/2<<"\n";
}
}
return 0;
}