原题地址一个一个模拟肯定要超时,只有生算找规律呗。比如n=4,k=10,先将n=4的所有排列写出来:(1) 1 2 3 4(2) 1 2 4 3(3) 1 3 2 4(4) 1 3 4 2(5) 1 4 2 3(6) 1 4 3 2(7) 2 1 3 4(8) 2 1 4 3(9) ...
分类:
其他好文 时间:
2015-01-27 17:54:23
阅读次数:
123
一、 题目
这道题给出一个数列,求大于这个数列的最小数列。
例如:
1,2,3 → 1,3,2
3,2,1 → 1,2,3
1,1,5 → 1,5,1
二、 分析
喜欢使用C++的童鞋或许会马上想到next_permutation()这个库函数,没错,其实这道题就是实现的它(严格说来只是初步实现),如果可以的话,如果直接输入这一行代码就可通过:
void...
分类:
其他好文 时间:
2015-01-25 01:26:02
阅读次数:
208
#include"iostream"#include"stdio.h"#include"string.h"#include"algorithm"#include"stdlib.h"using namespace std;char s[100];int main(){ int t; cin...
分类:
其他好文 时间:
2015-01-24 22:44:13
阅读次数:
212
Given a collection of numbers, return all possible permutations.
For example,
[1,2,3] have the following permutations:
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2],
and [3,2,1].
全排列,从全体元素中挑一个...
分类:
其他好文 时间:
2015-01-24 17:27:49
阅读次数:
147
奇怪了,做全排列的时候,在交换两个数时用到algorithm中的swap函数,效率竟然比自己写一个swap的效率差,是因为大量进行调用的原因吗?求解....
full_permutation 为我写的计算全排列数量的函数,没有使用algorithm中的swap函数,
nextPerm 使用了algorithm中的next_permutation函数,
full_permutation_...
分类:
其他好文 时间:
2015-01-23 13:32:46
阅读次数:
203
这道题我一开始的想法是:把每个需要交换的都交换了,循环n次肯定就是结果,n又比较小不会超时。但是这种想法too young,因为它无法交换需要间接交换的两个数。所以一种正确解法是:找出能间接交换的所有i和j,把对应的A[i][j]=A[j][i]='1',之后只需扫一遍整个矩阵把要换的换了就是最终结...
分类:
其他好文 时间:
2015-01-23 12:45:09
阅读次数:
226
http://acm.hdu.edu.cn/showproblem.php?pid=1716考到题目直接套 next_permutation 没有注意到0不能为首位 结果wa了一整天输出结构也略有些小坑#include#include#include#include#includeusing nam...
分类:
其他好文 时间:
2015-01-23 10:53:50
阅读次数:
119
给一个排列 求下一个排列 按字典序
跟普通排列不同的地方就是 有相同的数字
那么就把普通的一改就完事
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAXN 222
#define MAXM 6122222
#define INF 10000...
分类:
其他好文 时间:
2015-01-23 06:14:40
阅读次数:
182
背景:1Y,最简单的密码学!
思路:把每个字符串中每个字母的频数统计 出来,把频数相同的两个数映射就可,如果最后所有字母都有对应的映射,那么就是YES,permutation cipher不需要管。
学习:
1.C语言stdlib.h里的qsort函数原型:void qsort(void * base,size_t num,size_t size,int (*comparator)(c...
分类:
其他好文 时间:
2015-01-22 11:06:37
阅读次数:
151
题目:
The set [1,2,3,…,n] contains a total of n! unique
permutations.
By listing and labeling all of the permutations in order,
We get the following sequence (ie, for n = 3):
"123""132""213"...
分类:
编程语言 时间:
2015-01-20 22:19:05
阅读次数:
209