hdu1716(库函数next_permutation)
题目意思:
现有四张卡片,用这四张卡片能排列出非常多不同的4位数,要求按从小到大的顺序输出这些4位数。
注意首位没有前导0
pid=1716">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)的更多相关文章
- 【字母全排列】 poj 1256
深搜 注意与STL模版的去重函数唯一的区别就是有去重. #include <iostream> #include <cstdio> #include <string. ...
- LeetCode(47)Permutations II
题目 Given a collection of numbers that might contain duplicates, return all possible unique permutati ...
- hdu1716排列2(stl:next_permutation+优先队列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- c++中STL中的next_permutation函数基本用法
对于next_permutation函数是针对于排列组合问题的库函数,它的排序方式是按照字典的方式排列的·: 如以下代码对于next_permutation函数的初步解释: #include<c ...
- 【LeetCode】数组排列问题(permutations)(附加next_permutation解析)
描述 Given a collection of distinct integers, return all possible permutations. Example: Input: [1,2,3 ...
- CPP常用库函数以及STL
其他操作 memset void * memset ( void * ptr, int value, size_t num ); memset(ptr,0xff,sizeof(ptr)); 使用mem ...
- Entity Framework 6 Recipes 2nd Edition(11-11)译 -> 在LINQ中调用数据库函数
11-11. 在LINQ中调用数据库函数 问题 相要在一个LINQ 查询中调用数据库函数. 解决方案 假设有一个任命(Appointment )实体模型,如Figure 11-11.所示, 我们想要查 ...
- Linux系统调用和库函数调用的区别
Linux下对文件操作有两种方式:系统调用(system call)和库函数调用(Library functions).系统调用实际上就是指最底层的一个调用,在linux程序设计里面就是底层调用的意思 ...
- 关于全排列 next_permutation() 函数的用法
这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...
随机推荐
- [Apple开发者帐户帮助]三、创建证书(7)创建证书签名请求
Mac上的Keychain Access允许您创建证书签名请求(CSR). 启动位于的Keychain Access /Applications/Utilities. 选择Keychain Acces ...
- POJ 1149 PIGS (AC这道题很不容易啊)网络流
PIGS Description Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlo ...
- 看懂SqlServer执行计划
在园子看到一篇SQLServer关于查询计划的好文,激动啊,特转载.原文出自:http://www.cnblogs.com/fish-li/archive/2011/06/06/2073626.htm ...
- WebGL画点程序v2
本文程序实现画一个点的任务,如下图.其中,点的位置坐标由Javascript传到着色器程序中,而不是直接给定("硬编码")在顶点着色器中. 整个程序包含两个文件,分别是: 1. H ...
- 读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++]
读书笔记之:C++ Primer (第4版)及习题(ch01-ch11) [++++] 第2章 数据和基本类型 1. 整型 2. 习题:左值和右值 3. C++关键字/保留字和操作符替代值 4. 声明 ...
- Ceph 文件系统的安装
yum install -y wget wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87 ...
- openstack--rabbitmq
一.MQ 全称为 Message Queue, 消息队列( MQ ) 是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们. 消息传 ...
- 单链表每k个节点为一组进行反转(最后不满k个时不反转)
public class LinkReverse2 { public static Node mhead=null; public static Node mtail=null; public sta ...
- Java 各级注解及@Autowired注入为null解决办法
1.@controller 控制器 用于标注控制层,相当于struts中的action层. 2.@service 服务层 用于标注服务层,主要用来进行业务的逻辑处理. 3.@repository DA ...
- PAT_A1143#Lowest Common Ancestor
Source: PAT A1143 Lowest Common Ancestor (30 分) Description: The lowest common ancestor (LCA) of two ...