排列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() ...
随机推荐
- 教你如何禁用U盘、屏蔽USB端口的三种方法
如果想禁止所有U盘的使用,则可以通过修改注册表来实现. 打开”运行“对话框,输入命令“Regedit”进入注册表界面. 依次展开“HKEY_LOCAL_MACHINE”→“SYSTEM”→“ Cu ...
- powerdesigner 导出excel
PD菜单栏中,依次点击 Tools ->Excute Commands->Edit/Run Script.. 填入 '*********************************** ...
- spring boot @ConditionalOnxxx相关注解总结
Spring boot @ConditionalOnxxx相关注解总结 下面来介绍如何使用@Condition public class TestCondition implements Condit ...
- Graph-DFS-Map-图的深度优先遍历-城市地图问题
#include <iostream> using namespace std; /* 5 8 1 2 2 1 5 10 2 3 3 2 5 7 3 1 4 3 4 4 4 5 5 5 3 ...
- SWT中ole/activex实践--操作word的一个例子
http://setting.iteye.com/blog/747295 ———————————————————————————————————————————————— 这几年,做了很多word/e ...
- [hadoop读书笔记] 第四章 Hadoop I/O操作
P92 压缩 P102 序列化 序列化:将结构化对象转为字节流便于在网上传输或写到磁盘进行永久性存储的过程 用于进程之间的通信或者数据的永久存储 反序列化:将字节流转为结构化对象的逆过程 Hadoop ...
- Qt之QLocalSocket
简述 QLocalSocket类提供了一个本地socket. 在Windows中,这是一个命名管道:在Unix中,这是一个本地网域socket. 如果发生错误,socketError()会返回错误的类 ...
- numpy opencv matlab eigen SVD结果对比
参考 https://zhuanlan.zhihu.com/p/26306568 https://byjiang.com/2017/11/18/SVD/ http://www.bluebit.gr/m ...
- 3种启动tornado的方式
r"""A non-blocking, single-threaded HTTP server. 翻译: 一个非阻塞的单线程HTTP服务器 A server is def ...
- 3ds Max 中的导航控件SteeringWheels入门介绍
介绍 软件环境:3d Max2015 SteeringWheels 3D导航控件也可以说是“追踪菜单”,通过它们可以使用户从单一的工具访问不同的2D和3D导航工具.SteeringWheels可分成多 ...