排列2(全排列next_permutation 注意格式)
排列2
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7993 Accepted Submission(s): 2967
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
每组输出数据间空一行,最后一组数据后面没有空行。
1 1 2 3
0 1 2 3
0 0 0 0
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; int main(){
int a[];
int flot = ;
while(){ int x = ;
for(int i = ; i < ; i++){
scanf("%d", a + i);
x |= a[i];
}
sort(a, a + );
if(!x)break; if(flot)puts("");
flot ++;
int p = a[];
bool kg = false;
do{
if(a[] == )continue;
if(a[] == p){
if(kg)printf(" ");
}else{
if(p)puts("");
p = a[]; }
kg = true; for(int j = ; j < ; j++){
printf("%d", a[j]);
} }while(next_permutation(a, a + ));
printf("\n");
}
return ;
}
排列2(全排列next_permutation 注意格式)的更多相关文章
- 7.2.1 生成1~n的排列(全排列)【STL__next_permutation()_的应用】
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> ...
- 全排列next_permutation()用法和构造函数赋值
全排列next_permutation()用法 在头文件aglorithm里 就是1~n数组的现在的字典序到最大的字典序的依次增加.(最多可以是n!种情况) int a[n]; do{ }while( ...
- 关于全排列 next_permutation() 函数的用法
这是一个c++函数,包含在头文件<algorithm>里面,下面是基本格式. 1 int a[]; 2 do{ 3 4 }while(next_permutation(a,a+n)); 下 ...
- 全排列 next_permutation() 函数的使用
看来看去还是这篇博客比较简洁明了 https://www.cnblogs.com/My-Sunshine/p/4985366.html 顺便给出牛客网的一道题,虽然这道题用dfs写出全排列也能做,题意 ...
- 排列组合函数next_permutation()
next_permution(),按照字典序进行排列组合, 括号里的参数为类似sort里面的参数,用法相同 #include <bits/stdc++.h> using namespace ...
- HDOJ 1716 排列2(next_permutation函数)
Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡 ...
- 全排列 next_permutation 用法
给一个正整数n,让你求它的全排列 先介绍一个函数,iota(a,a+n,1) 用法就是把a数组的第0位到第n-1位依次赋为1,2,.....n: 然后是next_permutation(a,a+4)函 ...
- 全排列 next_permutation() 函数的用法
在头文件<algorithm>里面有如下代码: int a[]; do { } while(next_permutation(a,a+n)); 可产生1~n的全排列有如下代码: #incl ...
- 排列算法汇总(下一个排列,全排列,第K个排列)
一.下一个排列 首先,STL提供了两个用来计算排列组合关系的算法,分别是next_permutation和prev_permutation. next_permutation(nums.begin() ...
随机推荐
- Sql Over的用法
转载自:http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html OVER(PARTITION BY)函数介绍 开窗函数 Oracle从 ...
- mysq在某一刻同时获取主从库的位置点
在从库进行锁表操作flush table with read lock, 通过show slave status\G 获取对应主库的位置点: show slave status\G********** ...
- 【C】——使用creat()函数需要注意的事项
#include<fcntl.h> int creat(const char *pathname, mode_t mode); 若成功则返回为只写打开的文件描述符,若出错则返回-1: 有时 ...
- java socket 服务端 客户端
Server package com.witwicky.socket.basicsocket; import java.io.IOException; import java.io.InputStre ...
- 数据框排序 data.frame order
# sorting examples using the mtcars datasetattach(mtcars) # sort by mpgnewdata <- mtcars[order(mp ...
- USB学习笔记连载(二十):FX2LP如何实现高速和全速切换(转载)
CYPRESS的USB外设控制器CY7C68013A是一款广泛应用于USB打印机,手机,存储设备,USB测试等多个领域的经典产品.该产品符合USB2.0协议规范,支持full speed和high s ...
- Axure RP Pro 7.0 注册码
用户名:aaa注册码:h624pifAqt7It5e8boKkML+Y4RjDX5xknP4k7QktJYQoxsvv7VUS7hBCv/2ef45P
- Linux强制杀进程命令行工具
需求, 有时候我们会有手动启动程序, 但是又在后台, 没有像服务那样有start, 和stop的程序, 这时候需要用强制杀进程方式 涉及工具, awk, sed, xargs, kill 需求一: 已 ...
- js 获取单选框和复选框的值和js dom方法给单选框和多选框赋值
获取单选框框值的方法 function getRadioRes(Name){ var rdsObj = document.getElementsByName(Name); var checkVal = ...
- 【转】【CentOS】【Python】Centos7安装Python3的方法
由于centos7原本就安装了Python2,而且这个Python2不能被删除,因为有很多系统命令,比如yum都要用到. [root@VM_105_217_centos Python-3.6.2]# ...