题解:CF2059B Cost of the Array
Hack_Table · · 题解
题目意思
让你将
思路
这题有点像脑筋急转弯。 \
如果
- 如果这个区间全是
1 的话,我们就选择两个1 ,答案就为2 。 - 如果这个区间有其它数的话,我们就选择其它数,答案就为
1 。
接着,我们就做完了。
代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n,a[200005],k;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if (n==k){
int sum=1,ans=k/2+1;
for(int i=2;i<=n;i+=2,sum++){
if (sum!=a[i]){
ans=sum;
break;
}
}
cout<<ans<<endl;
continue;
}
bool f=true;
for(int i=2;i<=n-k+2;i++){
if (a[i]!=1){
f=false;
break;
}
}
if (f){
cout<<2<<endl;
}else{
cout<<1<<endl;
}
}
return 0;
}