hdu2689 Sort it (树状数组)
2013-07-14 20:30
239 查看
#include <stdio.h> #include <string.h> #define MAX 1002 int arr[MAX],n; //树状数组 int lowBit(int x) { return (x&(-x)); } void add(int index) { while(index<=n) { arr[index]++; index+=lowBit(index); } } int func(int num) { int sum=0; while(num>0) { sum+=arr[num]; num-=lowBit(num); } return sum; } int main() { int i,ans,x; while(scanf("%d",&n)!=EOF) { ans=0; memset(arr,0,sizeof(arr)); for(i=1;i<=n;i++) { scanf("%d",&x); add(x); ans+=(i-func(x));//求得的逆序数 } printf("%d\n",ans); } return 0; }
相关文章推荐
- HDU2689 Sort it【树状数组】【逆序数】
- HDU 2689 Sort it(树状数组,逆序数)
- HDU2689 Sort it (树状数组求逆序数)
- hdu 2689 Sort it(树状数组)
- HDU 2689 Sort it【树状数组】
- HDU 2689 Sort it [树状数组]【数据结构】
- hdu 2689 sort it(树状数组 逆序数)
- hdu 2689 Sort it(树状数组)
- HDU 2689 Sort it (树状数组)
- hdu 2689 Sort it 一维树状数组的应用
- HDU 2689 Sort it 简单树状数组入门
- HDU-2689-Sort it
- HDU 2689 Sort it 树状数组
- hdu2689 Sort it (树状数组)
- HDU 2689 POJ 2299 树状数组 + 离散化
- HDU 2689 sort it - from lanshui_Yang
- HDU 2689 sort it - from lanshui_Yang
- 模板(线段树 + 树状数组 + 单点查询 + 区间查询)eg:HDU 1754 - I Hate It
- HDU 1754 I Hate It(树状数组求区间最值)
- HDU 2689 sort it