题解:CF1682B AND Sorting
思路
这题的思路很简单,没在该在的位置上,就要去按位与。关于是否有解,由于它是 的排列,所以一定可以排序,也一定有解。
code:
#include<bits/stdc++.h>
using namespace std;
int a[200005], cnt;
int main(){
int t, n;
cin >> t;
while(t --){
int ans;
cnt = 0;//多测要清空
cin >> n;
for(int i = 0; i < n; i ++){
int x;
cin >> x;
if(x != i) a[++ cnt] = x;//不在位置上
}
ans = a[1];
for(int i = 2; i <= cnt; i ++) ans = ans & a[i];
cout << ans << "\n";
}
return 0;
}
posted on 2024-06-06 18:58 zhangzirui66 阅读(9) 评论(0) 收藏 举报 来源