CF2117A
题目。
记 。
枚举 每个长度为 的区间,记区间内 的数量为 。
如果全部通过,当且仅当 。
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
#define ll long long
ll T,n,x,a[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
cin>>n>>x;
ll cnt=0,js=0;
bool f=0;
if(x>=n){
for(int i=1;i<=n;i++){
cin>>a[i];
cnt+=(a[i]==1);
}
cout<<"Yes\n";
}
else{
for(int i=1;i<=n;i++){
cin>>a[i];
cnt+=(a[i]==1);
}
for(int i=1;i<=n-x+1;i++){
for(int j=0;j<x;j++){
js+=(a[i+j]==1);
}
if(js==cnt){
f=1;
break;
}
js=0;
}
if(f) cout<<"Yes\n";
else cout<<"No\n";
}
}
return 0;
}CF2117B
题目。
构造题。
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
ll T,n,a[N];
bool bot[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
cin>>n;
ll mid=(n+1)/2,temp=n,ans;
a[mid]=n;
temp--;
bot[n]=1;
for(int i=1;i<=mid-1;i++){
a[mid+i]=temp;
bot[temp]=1;
temp--;
a[mid-i]=temp;
bot[temp]=1;
temp--;
}
for(int i=1;i<=n;i++){
if(!bot[i]) ans=i;
}
if(n%2) for(int i=1;i<=n;i++) cout<<a[i]<<' ';
else{
for(int i=1;i<n;i++) cout<<a[i]<<' ';
cout<<ans;
}
cout<<"\n";
for(int i=1;i<=n;i++) bot[i]=0;
}
return 0;
}一种简单的构造方法是:
难崩。
CF2117C
题目。
思维。
出现的数在后面都要出现一次。
维护两个 set , 表示所有出现过的数字, 表示新的分割段内的数字,可以分成新的一段当且仅当 。
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
ll T,n,a[N],ans;
set<ll>s,t;
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++){
s.insert(a[i]);
t.insert(a[i]);
if(s.size()==t.size()){
ans++;
t.clear();
}
}
cout<<ans<<'\n';
ans=0;
s.clear();
t.clear();
}
return 0;
}CF2117D
题目。
我们设进行操作一 次,操作二 次,则有:
推广开来有:
我们发现 可以得出一个二元一次方程组,进而可以求得 ,把 代入原式 check 一边即可。
注意 。
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
ll T,n,a[N];
bool check(ll x,ll y){
for(int i=1;i<=n;i++){
ll an=i*x+(n-i+1)*y;
if(an!=a[i]) return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>T;
while(T--){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
ll y=(2*a[1]-a[2])/(n+1);
ll x=a[1]-n*y;
if(check(x,y)&&x>=0&&y>=0) cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}