HDU 1716 排列2(排列生成,,next_permutation())
2012-08-04 15:17
337 查看
排列2
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2554 Accepted Submission(s): 991
[align=left]Problem Description[/align]
Ray又对数字的列产生了兴趣:
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
[align=left]Input[/align]
每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。
[align=left]Output[/align]
对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。
每组输出数据间空一行,最后一组数据后面没有空行。
[align=left]Sample Input[/align]
1 2 3 4 1 1 2 3 0 1 2 3 0 0 0 0
[align=left]Sample Output[/align]
1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321 1123 1132 1213 1231 1312 1321 2113 2131 2311 3112 3121 3211 1023 1032 1203 1230 1302 1320 2013 2031 2103 2130 2301 2310 3012 3021 3102 3120 3201 3210
[align=left]Source[/align]
2007省赛集训队练习赛(2)
[align=left]Recommend[/align]
lcy
用的next_permution()生成的排列。。
注意格式控制
#include<stdio.h> #include<algorithm> #include<iostream> using namespace std; int a[4]; int main() { //freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int t1,t2; bool first=true; while(1) { for(int i=0;i<4;i++) scanf("%d",&a[i]); sort(a,a+4); if(a[3]==0) { printf("\n"); break; } if(first) first=false; else printf("\n\n"); t1=0; while(1) { t2=a[0]*1000+a[1]*100+a[2]*10+a[3]; if(t2/1000>0&&t1!=t2) { if(t1==0) { printf("%d",t2); t1=t2; } else if(t1/1000!=t2/1000) { printf("\n%d",t2); t1=t2; } else { printf(" %d",t2); t1=t2; } } if(!next_permutation(a,a+4)) break; } } return 0; }
相关文章推荐
- HDU 1716 排列2 (stl,next_permutation)
- HDU1716 next_permutation 的简单应用 排列2
- hdu 1716 排列2(stl next_permutation)
- 全排列生成算法:next_permutation
- 全排列next_permutation的用法 HDU 1027 PKU 3187 1146 1731
- 7.2.1 生成1~n的排列(全排列)【STL__next_permutation()_的应用】
- (next_permutation) 排列2 hdu 1716
- hdu 1716 排列2(next_permutation函数应用)
- (排列生成算法)枚举排列的两种方法:递归枚举和next_permutation (使用多用next_permutation)
- hdu1716(库函数next_permutation)
- hdu 1027 hdu 1716 (next_permutation的使用)
- 杭电Problem-1716 排列2 next_permutation
- STL之生成全排列:next_permutation & prev_permutation
- STL源码——排列生成算法(next-permutation、pre-permutation)
- HDU 1027 Ignatius and the Princess II (产生第m大的排列,STLmap中的next_permutation(array,array+n);)
- HDOJ 1716 排列2 (next_permutation或dfs)
- 生成排列(next_permutation(a, a + n))
- 排列生成以及next_permutation的用…
- 全排列生成算法:next_permutation
- 全排列的生成使用C++的库函数:next_permutation