bzoj2058[Usaco2010 Nov]Cow Photographs 归并+逆序对
来源:互联网 发布:vb获取当前日期时间 编辑:程序博客网 时间:2024/06/06 00:51
具体不好形容。。
http://www.cnblogs.com/Sakits/p/5837039.html
顺便复习了一波归并排序。。
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<vector>#define fo(i,a,b) for(int i=a;i<=b;i++)#define fd(i,a,b) for(int i=a;i>=b;i--)using namespace std;typedef long long ll;const int N=1e5+5;int n,m;int a[N],b[N],tmp[N];int pos[N];ll ans;inline void mergesort(int l,int r){ if (l==r)return; int mid=(l+r)>>1; int cnt=l,h1=l,h2=mid+1; mergesort(l,mid); mergesort(mid+1,r); while (h1<=mid&&h2<=r) { while (b[h1]>b[h2]) { tmp[cnt++]=b[h2]; h2++; ans+=mid-h1+1; if (h2>r)break; } tmp[cnt++]=b[h1]; h1++; } fo(i,h1,mid)tmp[cnt++]=b[i]; fo(i,h2,r)tmp[cnt++]=b[i]; fo(i,l,r)b[i]=tmp[i];}int main(){ scanf("%d",&n); fo(i,1,n) { scanf("%d",&b[i]); pos[b[i]]=i; } mergesort(1,n); ll sum=ans; fo(i,1,n) { sum=sum-(pos[i]-1)+(n-pos[i]); ans=min(ans,sum); } printf("%lld\n",ans);}
0 0
- bzoj2058[Usaco2010 Nov]Cow Photographs 归并+逆序对
- 2058: [Usaco2010 Nov]Cow Photographs
- 树状数组 [Usaco2010 Nov]Cow Photographs
- bzoj2058Cow Photographs(逆序对)
- Cow Photographs
- 归并求逆序对
- 逆序对 归并排序
- 归并排序 & 逆序对
- 归并求逆序对
- 归并排序--逆序对
- 归并排序求逆序对
- poj1007 归并求逆序对
- 【归并排序】【逆序对】序列
- 归并排序与逆序对
- 归并排序求逆序对
- 归并排序求逆序对~~~
- 归并求逆序对【模板】
- 归并排序求逆序对
- Netty为啥可靠(二)
- 寻找字符串中的abc
- 免疫算法
- java学习之旅-javase(基础-01)
- 【信源编码作业】6. 最小均方算法(LMS)
- bzoj2058[Usaco2010 Nov]Cow Photographs 归并+逆序对
- VirtualBox 初次安装centos7 虚拟机的注意事项
- 内网穿透工具ngrok的使用
- hdu3723(卡特兰数组合数)
- bzoj2748
- 使用git命令上传本地项目到github
- AD的PCB板设计中PCB板的开槽
- Opacity兼容性
- C语言atoi、atof、atol、atrtod,strtol和strtoul