题目传送门

题意:训练指南P248

分析:逆向考虑,比如一个全排列:7345261,它也可以表示成题目中的形式,第一个数字7是由6 * (7 - 1)得到的,第二个数字3有2 * (7 - 2)得到,所以只要树状数组单点修改二分(找最远的因为有些位置是0)查询当前第s[i] + 1的数字(在BIT中指前p项和为s[i] + 1)。

#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
int s[N];
struct BIT {
int c[N], sz;
void init(int num) {
memset (c, 0, sizeof (c));
sz = num;
}
void updata(int i, int x) {
while (i <= sz) {
c[i] += x; i += i & -i;
}
}
int query(int i) {
int ret = 0;
while (i > 0) {
ret += c[i]; i -= i & -i;
}
return ret;
}
int bsearch(int l, int r, int kth) {
while (l < r) {
int mid = l + r >> 1;
if (query (mid) < kth) l = mid + 1;
else r = mid;
}
return r;
}
}bit; int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int k; scanf ("%d", &k);
bit.init (k);
for (int i=1; i<=k; ++i) {
scanf ("%d", &s[i]);
bit.updata (i, 1);
}
for (int i=1; i<=k; ++i) {
int p = bit.bsearch (1, k, s[i] + 1);
if (i > 1) printf (" ");
printf ("%d", p);
bit.updata (p, -1);
}
puts ("");
} return 0;
}

  

全排列 UVA 11525 Permutation的更多相关文章

  1. UVA 11525 Permutation(树状数组)

    题目意思是说  给你一个数k  然后有k个si   问你1--k 的第n个全排列是多少   注意是 1 2 3...k的全排列 不是si的 N=   由观察得知(k-i)!就是k-i个数字的全排列种数 ...

  2. UVA 11525 Permutation (树状数组+YY)

    题意:给你k个数Si,然后给你一个等式   H= ∑  Si ∗ (K − i)!  (i=(1->k)且0 ≤ Si ≤ K − i). 叫你求出第H个全排列 其实这是一个康托展开:X=a[n ...

  3. UVA 11525 Permutation ——(线段树,脑筋急转弯)

    只要注意到对于譬如:S1*(k-1)! 因为后面k-1个数字的全排列个数刚好是(k-1)!,那么第一个数字就是没有取过的数字的第(S1+1)个即可.取走这个数字以后这个数字就不能再用了,依次类推即可得 ...

  4. Permutation UVA - 11525(值域树状数组,树状数组区间第k大(离线),log方,log)(值域线段树第k大)

    Permutation UVA - 11525 看康托展开 题目给出的式子(n=s[1]*(k-1)!+s[2]*(k-2)!+...+s[k]*0!)非常像逆康托展开(将n个数的所有排列按字典序排序 ...

  5. uva 11525(线段树)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. 全排列 递归方法(permutation原理

    https://blog.csdn.net/axiqia/article/details/50967863  原博客 (一)递归的全排列算法 (A.B.C.D)的全排列为 1.A后面跟(B.C.D)的 ...

  7. [Swift]LeetCode267.回文全排列 II $ Palindrome Permutation II

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  8. UVA 11922 Permutation Transformer(平衡二叉树)

    Description Write a program to transform the permutation 1, 2, 3,..., n according to m instructions. ...

  9. uva 11922 Permutation Transforme/splay tree

    原题链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18902 伸展树的区间翻转剪切... 如下: #include< ...

随机推荐

  1. html与js传json值给php

    //一段js代码 var data = {}, act = [], list = []; $('.set').find('input, textarea').each(function() { act ...

  2. 35. Search Insert Position

    题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...

  3. October 1st 2016 Week 40th Saturday

    Autumn, the year's last, loveliest smile. 秋,四季流转中的最后一抹,也是最美的那一抹微笑. I love autumn because it is the h ...

  4. Android RadioButton selector背景

    RadioButton selector 背景 <?xml version="1.0" encoding="utf-8"?> <selecto ...

  5. postgresql集群方案参考答案

    PostgreSQL配置Streaming Replication集群 http://www.cnblogs.com/marsprj/archive/2013/03/04/2943373.html p ...

  6. spring刚开始学习搭建

    下载的软件包地址: http://repo.springsource.org/libs-release-local/org/springframework/spring 用maven进行快速开始: h ...

  7. python 连接sql server

    linux 下pymssql模块的安装 所需压缩包:pymssql-2.1.0.tar.bz2freetds-patched.tar.gz 安装: tar -xvf pymssql-2.1.0.tar ...

  8. Pyqt QSplashScreen启动画面

    多大数应用程序启动时都会在程序完全启动时显示一个启动画面,在程序完全启动后消失.程序启动画面可以显示一些有关产品的信息,让用户在等待程序启动的同时了解有关产品的功能,也是一个宣传的方式.QSplash ...

  9. react.js 多个组件集成示例

    这个看得有点懵, 可能要结合其它实例看. html <!DOCTYPE html> <html> <head> <script src="http: ...

  10. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...