uva 11525(线段树)
2013-09-08 23:42
288 查看
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2520
题意:有一个排列1~k,求第n个排列,其中n为
View Code
题意:有一个排列1~k,求第n个排列,其中n为
#include<stdio.h> #include<string.h> const int maxn=50000+10; int c[maxn],num[maxn]; int n; int lowbit(int x) { return x&(-x); } void update(int x,int num) { while(x<=n) { c[x]+=num; x+=lowbit(x); } } int sum(int x) { int ret=0; while(x>0) { ret+=c[x]; x-=lowbit(x); } return ret; } int binary(int x) { int low=1,high=n; while(low<=high) { int m=(low+high)>>1; int cnt=sum(m); if(cnt==x) { if(num[m]) return m; else high=m-1; } else if(cnt<x) low=m+1; else high=m-1; } return 0; } int main() { int t,i,x; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(c,0,sizeof(c)); for(i=1;i<=n;i++) num[i]=1; for(i=1;i<=n;i++) update(i,1); for(i=0;i<n;i++) { scanf("%d",&x); int cnt=binary(x+1); update(cnt,-1); num[cnt]=0; printf("%d",cnt); if(i!=n-1) printf(" "); } printf("\n"); } return 0; }
View Code
相关文章推荐
- UVA 11525 Permutation(线段树第K大数字问题)
- 线段树优化康拓展开uva11525
- UVA 11525 好大好大的排列(线段树)
- UVaLive 11525 Permutation (线段树)
- uva 11525 - Permutation(线段树)
- 【UVA】11525-Permutation(线段树水题)
- UVa 11525 - Permutation (线段树 树状数组 康托展开式)
- UVa 11525 Permutation (线段树)
- UVA 11992 (维护多棵线段树,区间更新,区间替换)
- UVA 1400 1400 - "Ray, Pass me the dishes!"(线段树)
- UVA 12299 RMQ with Shifts(线段树单点更新,最值查询)
- UVA1232 - SKYLINE(线段树区间修改)
- UVA 12299 - RMQ with Shifts(线段树)
- UVA 12299 RMQ with Shifts(线段树)
- UVa 12299 RMQ with Shifts(线段树)
- uva 11525 Permutation
- UVa 11992 Fast Matrix Operations (线段树区间修改大杂烩)
- UVA - 11525 Permutation
- UVALive3938 "Ray, Pass me the dishes!" 线段树动态区间最大和
- UVa 11297 Census 二维线段树模板