hdu2689 Sort it (树状数组)
来源:互联网 发布:电脑软件应用商店 编辑:程序博客网 时间:2024/05/13 11:12
#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 (树状数组)
- hdu2689 Sort it (树状数组)
- HDU2689 Sort it【树状数组】【逆序数】
- HDU2689 Sort it (树状数组|水题)
- HDU2689 Sort it (树状数组求逆序数)
- HDU2689 Sort it(树状数组求逆序数)
- HDU2689-树状数组&逆序数|分治-Sort it
- HDU2689:Sort it
- hdu2689 sort it
- hdu2689树状数组
- hdu2689树状数组
- hdu2689 树状数组 逆序数
- Sort It (树状数组+dp)
- HDU 2689 Sort it (树状数组)
- 杭电Sort it 2689树状数组
- HDU 2689 Sort it [树状数组]【数据结构】
- hdu 2689 Sort it(树状数组)
- HDU 2689 Sort it 树状数组
- 7zip使用
- android AutoCompleteTextView 自定义BaseAdapter
- java mvc
- 内存申请与一级二级指针
- PPP with MPPE协议
- hdu2689 Sort it (树状数组)
- M.L's visit work 3--- ros-rt-wmp on epuck
- web页面控件之-模拟页面alert提示
- 01-html Canvas标签的使用案例
- VC++中利用MSXML解析XML文档
- Longest Common Prefix
- oracle 分组学习
- 模n下大数幂乘的两个算法的基本运作原理
- Distinct Subsequences