HDU5592 ZYB's Premutation 树状数组应用
来源:互联网 发布:mac的ppt怎么调16:9 编辑:程序博客网 时间:2024/05/28 18:45
#include<iostream>#include<stdio.h>#include<string>#include<algorithm>using namespace std;int a[50005];//已知数组;int c[50005];//树状数组;int n; int lowBit(int x) //计算2^K的值,即下标为X的结点管辖的范围 { return x&(-x); } void modify(int pos,int num) //pos为数组下标位置,num为要增加的值 { while(pos<=n) //n为数组的长度 { c[pos]+=num; pos+=lowBit(pos); } } int getResult(int pos) //求A[1]+...+A[pos] { int sum=0; while(pos>0) { sum+=c[pos]; pos-=lowBit(pos); //下一个无联系的辖域 } return sum; } int findkth(int n,int k){ if(k-c[n]<=0){ int i=n; if(k-a[i]==0){ a[i]=0; modify(i,-1); return i; } else { findkth(n-1,k-a[i]); } } else findkth(n-lowBit(n),k-c[n]); }//寻找第k大的数的位置 void f(){ int t[50005]; int i; int b1=0,b2=0; scanf("%d",&n); for(i=1;i<=n;i++) { a[i]=1; modify(i,1); scanf("%d",&b2); t[i]=b2-b1; b1=b2; } for(i=n;i>0;i--) { t[i]=findkth(n,t[i]+1);//在i个数里寻找第t[i]+1大的数 } for(i=1;i<n;i++) printf("%d ",t[i]); printf("%d\n",t[n]);}int main(){ int T; cin>>T; while(T){ f(); T--; } return 0;}
已经忘记题意了~
0 0
- HDU5592 ZYB's Premutation 树状数组应用
- HDU5592 ZYB's Premutation(树状数组)
- hdu5592 ZYB's Premutation
- hdu5592-ZYB's Premutation
- HDU5592-ZYB's Premutation
- bestcoder#65ZYB's Premutation 树状数组+二分
- HDU 5592:ZYB's Premutation 树状数组+二分
- HDU 5592 ZYB's Premutation(二分+树状数组)
- BestCoder Round #65 HDOJ5592 ZYB's Premutation(树状数组+二分)
- HDU 5592 ZYB's Premutation(树状数组 + 二分)
- [hdu 5592 ZYB's Premutation] 树状数组+二分 求第K大数
- HDOJ 5592 ZYB's Premutation(逆序对变题:树状数组+二分||线段树)
- ZYB's Premutation POJ5592
- BC65 ZYB's Premutation
- hdu 5529 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- 一种服务器日志管理方法及系统
- WPF编译时提示"xxx不包含适合于入口点的静态 Main方法xxx"
- TurtleBot:从Hydro到Indigo的一些变更
- Struts2中属性驱动与模型驱动
- 多线程学习(十二)新特征-有返回值的线程
- HDU5592 ZYB's Premutation 树状数组应用
- DTU原理及基础知识
- AVFormatContext结构体源码解析
- 深入浅出学Hive——Hive安装与配置
- 一段常用的加解密代码demo
- zigbee基础应用(五)uart串口通信
- Android 4.4前后版本读取图库图片和拍照完美解决方案
- shell 脚本之for
- 如何计算润几月