标签:init div namespace include += for == scanf else
1 #include<bits/stdc++.h> 2 #define maxn 3005 3 using namespace std; 4 int n,a[maxn],t[maxn]; 5 int msort(int l,int r){ 6 if(l==r) return 0; 7 8 int m=l+r>>1; 9 int t1=msort(l,m); 10 int t2=msort(m+1,r); 11 12 int t3=0; 13 int i=l,j=m+1,k=l; 14 while(i<=m&&j<=r){ 15 if(a[i]>a[j]){ 16 t3+=m-i+1; 17 t[k++]=a[j++]; 18 } 19 else{ 20 t[k++]=a[i++];//本来就应该小于 21 } 22 } 23 while(i<=m) t[k++]=a[i++]; 24 while(j<=r) t[k++]=a[j++]; 25 26 for(int p=l;p<=r;p++) a[p]=t[p];//调整 27 return t1+t2+t3; 28 } 29 void init(){ 30 scanf("%d",&n); 31 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 32 int nd=msort(1,n); 33 if(nd&1){ 34 printf("%lf",(double)(2*nd-1)); 35 } 36 else printf("%lf",(double)2*nd); 37 } 38 int main(){ 39 init(); 40 41 return 0; 42 }
标签:init div namespace include += for == scanf else
原文地址:https://www.cnblogs.com/degage/p/9681704.html