题意:给2~10个不同的数字,要求把这些数字分成两堆,每一堆任意组合成一个数(开头不能为0),求两个数差的最小值。
思路:数据很小,直接暴力枚举所有情况,并且很容易想到,要使差最小则这两个数的位数应该尽量相等;枚举排列时用到了next_permutation函数。...
分类:
其他好文 时间:
2015-03-03 22:16:38
阅读次数:
265
题意:输出一个排列的后继排列,如果是最大的降序排列,则输出没有后继。
思路:调用STL中的next_permutation()函数即可。不过这个函数在求后继时是一个循环状态,即全升序是全降序的后继,循环回来了。所以在调用之前判断一下是否为全降序序列即可。 感觉用这个函数没什么技术含量,有时间用纯C写一个。
Code:
#include
#include
#include
usi...
分类:
其他好文 时间:
2015-02-27 13:34:29
阅读次数:
113
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl...
分类:
其他好文 时间:
2015-02-25 11:34:39
阅读次数:
160
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible...
分类:
其他好文 时间:
2015-02-24 21:04:51
阅读次数:
218
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl...
分类:
其他好文 时间:
2015-02-10 15:08:45
阅读次数:
143
http://poj.org/problem?id=3187
/*总结:头文件#include ,
next_permutation(num,num+n)生成数组num的全排列,
*/
#include
#include
using namespace std;
int fun(int *num,int n)
{
int num1[10];//不能直接使用num操作,涉及内存管理,需要用替...
分类:
其他好文 时间:
2015-02-10 11:18:36
阅读次数:
234
之前被教过一个next_permutation库函数,是用来实现数的全排列的,具体实现见代码#include#include#includeusing namespace std;int main(){ int a[1000]; int n; while(scanf("%d",&n...
分类:
其他好文 时间:
2015-02-07 00:29:22
阅读次数:
536
题意较复杂,请参见原题=_=||没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列。STL里的next_permutation函数真是好用。比较蛋疼的就是题目的输入了。。还有就是不明白,为什么19、20行注释哪错了?? 1 #include 2 using namespac....
分类:
其他好文 时间:
2015-02-06 00:39:51
阅读次数:
206
题目链接:Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it a...
分类:
其他好文 时间:
2015-02-04 23:22:50
阅读次数:
237
题目:
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest...
分类:
其他好文 时间:
2015-02-04 14:44:10
阅读次数:
136