UVa 941 - Permutations
来源:互联网 发布:两组数据相关性分析 编辑:程序博客网 时间:2024/05/29 17:40
題目:已知一個字母的有序集合,求出排第n的串。
分析:組合數學、字符串。康拓展開。
說明:注意對字符排序,UVa終於進前300名了╮(╯▽╰)╭。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;char buf[22];long long factorial[22];void cantor_expansion(long long n, int m){for (int i = m-1; i >= 0; -- i) {long long index = n/factorial[i], count = 0;for (int j = 0; j < m; ++ j) {if (buf[j]) {if (count == index) {printf("%c",buf[j]);buf[j] = 0;break;}else {count ++;}}}n %= factorial[i];}puts("");}int main(){factorial[0] = 1LL;for (int i = 1; i < 21; ++ i)factorial[i] = factorial[i-1]*i;long long n, m;while (~scanf("%lld",&m))while (m --) {scanf("%s%lld",buf,&n);sort(buf, buf+strlen(buf));cantor_expansion(n, strlen(buf));} return 0;}測試數據:
1abcdefghijklmnopqrst888888888888888881abcdefghijklmnopqrst2432902008176639999
0 0
- UVa 941 - Permutations
- UVa 941: Permutations 排列?其实是阶乘
- UVa:11925 Generating Permutations
- UVa 11925 - Generating Permutations
- UVa 11925 Generating Permutations
- UVa - 11925 - Generating Permutations
- UVA 11925 Generating Permutations
- UVA 11925 - Generating Permutations
- Generating Permutations UVA
- Uva-11630-Cyclic antimonotonic permutations
- UVA - 11925 Generating Permutations 推理
- UVA 11925(p254)----Generating Permutations
- Find the Permutations [Uva 11077]
- UVa 11077 Find the Permutations / 置换
- UVA 11077 Find the Permutations(置换+dp)
- UVA 11077 - Find the Permutations(递推)
- uva 11077 - Find the Permutations(置换)
- UVA - 11077 Find the Permutations (置换)
- 利用platform库获取浏览器和操作系统版本
- 脑残的低级错误之静态成员变量
- lua得到一个真随机数字
- 使用Java和Scala在IDE中开发DataFrame实战
- 编写一个简单的SSH例子
- UVa 941 - Permutations
- ListView分页加载
- JS学习13(表单脚本)
- PAT L2-007. 家庭房产 (并查集)
- 笔记
- Linux那些事儿之我是Sysfs(final)后记
- Jquery ajax 跨域访问
- 编程小练习
- android4.2系统增永不休眠同时隐藏休眠选项