hdu 2689 Sort it
2015-04-23 19:37
309 查看
/* *********************************************** Author :xryz Email :523689985@qq.com Created Time :4-22 21:15:18 File Name :hdusortit.cpp ************************************************ */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; int main() { int n,a[1024],i,j,ans,t; while(~scanf("%d",&n)) { ans=0; memset(a,0,sizeof(a)); for(i=0;i<n;i++) { scanf("%d",&a[i]); for(j=0;j<i;j++) { if(a[j]>a[i]) ans++; } } printf("%d\n",ans); } return 0; }
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int c[1024],b[1024]; int lowbit(int x) { return x&-x; } int sum(int *p,int x) { int ret=0; while(x>0) { ret+=p[x]; x-=lowbit(x); } return ret; } void add(int *p,int x,int d) { while(x<1024) { c[x]+=d; x+=lowbit(x); } } int main() { int i,ans,n,t; while(~scanf("%d",&n)) { memset(c,0,sizeof(c)); //memset(b,0,sizeof(b)); //memset(num,0,sizeof(num)); ans=0; for(i=1;i<=n;i++) { scanf("%d",&t); add(c,t,1); ans+=sum(c,n)-sum(c,t); } printf("%d\n",ans); } return 0; }
相关文章推荐
- HDU 2689 Sort it
- HDU 2689 Sort it(逆序对-BIT)
- HDU - 2689 Sort it与2016蓝桥杯B 交换瓶子 排序(相邻交换与任意交换)
- HDU 2689 sort it - from lanshui_Yang
- HDU 2689 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 - from lanshui_Yang
- HDU 2689 Sort it(树状数组)(类似逆序数,同样不需要离散化)
- HDU 2689 Sort it
- hdu 2689 Sort it
- HDU - 2689 Sort it
- hdu2689 Sort it
- HDU 2689 HDOJ 2689 Sort it ACM 2689 IN HDU
- HDU-2689-Sort it
- HDU_2689_Sort it