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)); 下 ...
随机推荐
- php循环跳出
PHP中的循环结构大致有for循环,while循环,do{} while 循环以及foreach循环几种,不管哪种循环中,在PHP中跳出循环大致有这么几种方式: 代码: <?php $i = 1 ...
- Android PopWindow的替代品BasePopup
版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/109 背景描述 最近一段时间,又看到了这个开源项目Base ...
- Your configuration specifies to merge with the ref 'refs/heads/v.autoCheckProduct.20190325' from the remote, but no such ref was fetched.
问题: 创建新的分支,当我们执行git pull,出现如下错误 解决办法: 1.切换到主分支(或者被依赖的分支,也就是你从哪个分支上拉取新的分支),博主这里是master分支 2.执行以下两个命令 3 ...
- iTex导出PDF
iText导出PDF,所需jar包如下: itext-asian-5.2.0.jar 支持导出中文的jar包 itextpdf-5.5.9.jar PDF核心jar包 bcprov-jdk15on-1 ...
- RecastNavigation(3D场景建模、网格导航)
一.RecastNavigation详解 RecastNavigation定义: RecastNavigation是一个导航寻路工具集,使用邻接的凸多边形集合描述一个3D场景,A*寻路算法使3D场景的 ...
- 2015 多校赛 第二场 1006 (hdu 5305)
Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...
- PHP 二维数组排序 可以按指定 键值排序
<?php header("Content-Type:utf-8"); $arr = array( 0 => array( 'name' => '国际原油价格', ...
- Git教程(3)git工作区与文件状态及简单示例
基础 目录: working driectory 工作目录,就是我们的工作目录,其中包括未跟踪文件及暂存区和仓库目录. staging area 暂存区,不对应一个具体目录,其实只是git di ...
- SQLServer2008 表连接时null 和 null 无法匹配?
例如 select * from tbl_a a left join tbl_b b on b.docno=a.docno and b.project=a.project where a.docno= ...
- 多种效果进度指示层效果iOS源码项目
该源码是一个多种效果进度指示层效果源码案例,源码KVNProgress,KVNProgress提供多种效果的进度指示层,有半透明效果,也支持全屏显示.指示层还高度支持自定义,可以按自己的需求定制.效果 ...