标签:des style blog color os io for div
//============================================================================ // Name : B.cpp // Author : L_Ecry // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include<cstring> #include<cstdio> #include<algorithm> #define N 5050 using namespace std; int c[N]; int a[N]; int lowbit(int t) { return t&(-t); } void add(int p,int x) { while(p<N) { c[p]+=x; p+=lowbit(p); } } int sum(int p) { int res=0; while(p>0) { res+=c[p]; p-=lowbit(p); } return res; } int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;++i) { scanf("%d",&a[i]); a[i]++; c[i]=0; } int all=0; for(int i=n;i>0;--i) { all+=sum(a[i]); add(a[i],1); } int ans=all; for(int i=1;i<=n;++i) { all+=(n-a[i])-(a[i]-1); if(all<ans) ans=all; } printf("%d\n",ans); } return 0; }
HDU 1394 Minimum Inversion Number,布布扣,bubuko.com
HDU 1394 Minimum Inversion Number
标签:des style blog color os io for div
原文地址:http://www.cnblogs.com/L-Ecry/p/3871417.html