|非正经题解|座位问题
2025-02-10 10:33:43
发布于:江苏
2阅读
0回复
0点赞
#include<iostream>
#include<vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin>>T;
while(T--){
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;++i){
cin>>a[i];
}
int c=0;
for(int i=0;i<n;++i){
if(a[i]==i+1){
c++;
}
}
if(c==0) {
cout<<"0\n";
}else{
if(c%2==0){
cout<<c/2<<'\n';
}else{
cout<<(c-1)/2+1<<'\n';
}
}
}
return 0;
}
这里空空如也
有帮助,赞一个