题解:P13364 [GCJ 2011 Qualification] GoroSort
思路
首先每一次操作回到原位的数字的期望个数与原本的序列无关。
考虑如果我们拿
延申一下,考虑我们现在有
因为每次操作回到原位的数的个数的期望小于等于
代码
#include<bits/stdc++.h>
using namespace std;
int t, n, ans;
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> t;
for(int tt = 1; tt <= t; tt ++){
cin >> n;
ans = 0;
for(int i = 1; i <= n; i ++){
int x;
cin >> x;
if(x != i){
ans ++;
}
}
cout << "Case #" << tt << ": " << ans << ".000000\n";
}
return 0;
}