hdu1716(库函数next_permutation)
来源:互联网 发布:链轮尺寸计算软件 编辑:程序博客网 时间:2024/05/13 05:10
题目意思:
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
注意首位没有前导0
http://acm.hdu.edu.cn/showproblem.php?pid=1716
题目分析:
库函数next_permutation()应用,直接调用库函数,输出时注意前导0,和空格,祥见代码
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int a[4],ok=0;
cin>>a[0]>>a[1]>>a[2]>>a[3];
while(1){
if(a[0]+a[1]+a[2]+a[3]==0) break;
sort(a,a+4);//排序
int k=a[0];
if(a[0]!=0) cout<<a[0]<<a[1]<<a[2]<<a[3];
while(next_permutation(a,a+4)){
if(a[0]==k&&a[0]!=0) cout<<" "<<a[0]<<a[1]<<a[2]<<a[3];
else{
if(a[0]!=0){
if(k!=0) cout<<endl;//换行
cout<<a[0]<<a[1]<<a[2]<<a[3];
}
k=a[0];
}
}
cout<<endl;
cin>>a[0]>>a[1]>>a[2]>>a[3];//只有下次不退出才换行
if(a[0]+a[1]+a[2]+a[3]!=0) cout<<endl;
}
return 0;
}
- hdu1716(库函数next_permutation)
- HDU1716 -- 全排列 -- STL -- next_permutation()
- 库函数next_permutation
- hdu1716 STL next_permutation函数的使用
- HDU1716 排列2 next_permutation的用法
- HDU1716 next_permutation 的简单应用 排列2
- 实现库函数next_permutation()
- hdu1716排列2(stl:next_permutation+优先队列)
- hdu1716
- hdu1716
- HDU1716
- poj 1833 排列 库函数 next_permutation 的调用
- next_permutation(求全排列的库函数)
- 方格填数(STL next_permutation库函数(全排列)求解)+ next_permutation库函数样例讲解
- C++库函数next_permutation的递归实现(数组全排列)
- 全排列的生成使用C++的库函数:next_permutation
- POJ-1731 Orders(排序全排列库函数next_permutation())
- next_permutation
- C#迁移winfrom项目出现CL.EXE -1问题的解决方案
- linux下maven2和maven3共存
- 通过WM_COPYDATA消息完成进程间通信
- dp与px转换
- 【例 2.10】
- hdu1716(库函数next_permutation)
- 项目六:穷举法解决组合问题(6)让计算机解决奥数题
- hdu 5083 有坑+字符串模拟水题
- system.web/identity@impersonate 设置为 true,解决方案
- 翻转字符串
- hdu1799(用递推公式求组合的个数)
- 第九周单步调试
- 记录字符操作函数(包括对应宽字符函数)
- [LeetCode] Find Minimum in Rotated Sorted Array II (包含递增和递减旋转,含有重复数字)