HDU1716(全排列)
排列2
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7151 Accepted Submission(s): 2723
Problem Description
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
Input
Output
每组输出数据间空一行,最后一组数据后面没有空行。
Sample Input
Sample Output
//2016.8.30
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set> using namespace std; int a[], vis[], ans[];
set<int> s; void dfs(int step)
{
if(step == )
{
int tmp = *ans[]+*ans[]+*ans[]+ans[];
s.insert(tmp);
return ;
}
for(int i = ; i < ; i++)
{
if(step == && a[i] == )continue;
if(vis[i])continue;
vis[i] = ;
ans[step] = a[i];
dfs(step+);
vis[i] = ;
}
} int main()
{
int pre, cnt = ;
while(scanf("%d%d%d%d",&a[],&a[],&a[],&a[]))
{
if(!a[]&&!a[]&&!a[]&&!a[])break;
if(cnt)cout<<endl;
cnt = ;
s.clear();
sort(a, a+);
memset(vis, , sizeof(vis));
dfs();
for(set<int>::iterator it = s.begin(); it != s.end(); it++)
{
int tmp = *it;
if(it==s.begin()){
cout<<tmp;
pre = tmp/;
}else
{
if(tmp/ == pre)cout<<" "<<tmp;
else {
cout<<endl<<tmp;
pre = tmp/;
}
}
}
cout<<endl;
} return ;
}
HDU1716(全排列)的更多相关文章
- 全排列-hdu1716
题目描述: 题目意思很简单,就是要我们输出全排列后的数据组成,但是要注意组成的数据是一个实数,并且千位数字相同的处在同一行中. 代码实现: #include<stdio.h> #inclu ...
- PHP实现全排列(递归算法)
算法描述:如果用P表示n个元素的全排列,而Pi表示n个元素中不包含元素i的全排列,(i)Pi表示在排列Pi前面加上前缀i的排列,那么n个元素的全排列可递归定义为: ① 如果n=1,则排列P只有一 ...
- hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)
xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串. (题于文末) 知识点: n个元素,其中a1,a2,··· ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- [LeetCode] Permutations 全排列
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...
- 全排列算法的JS实现
问题描述:给定一个字符串,输出该字符串所有排列的可能.如输入“abc”,输出“abc,acb,bca,bac,cab,cba”. 虽然原理很简单,然而我还是折腾了好一会才实现这个算法……这里主要记录的 ...
- java实现全排列
前天上午的面试遇到了一个用java实现一串数字的全排列的题,想来想去用递归最方便,可是没有在规定的时间内完成555,今天上午有空便继续写,以下是完成后的代码: import java.util.Arr ...
随机推荐
- input限定文件上传类型:Microsoft Office MIME types
<input id = " " name = " " type = " file " accept=" ? ? ? &quo ...
- (简单) POJ 2253 Frogger,Dijkstra。
Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Fro ...
- CodeForces 625D Finals in arithmetic
神奇的构造题,我的思路比较奇葩.搞了好久,看到WA on 91我绝望了,然后自己造数据,找到了错误,总算是AC了,现在是凌晨0:24分,看到AC之后,感动China! 我写的代码无比的长.....应该 ...
- CSS3样式linear-gradient的使用(切角效果)
linear-gradient linear-gradient是CSS3中新增的样式,主要用于颜色的渐变效果.MDN地址 linear-gradient在不同内核下使用方式不同,详细内容可参考w3cp ...
- STM8的中断系统以及外部中断详解
STM8具有最多32的中断系统,在中断的处理上类似于cortexm系列的芯片,首先是每个中断的向量都是固化在系统内部的,用户需要向相应的中断向量flash位置写入中断处理函数,其二,每个中断向量都具有 ...
- Phone APP设计规范/iPad APP设计规范/Android APP设计规范/网页设计规范
原文链接:http://www.ui001.com/chicun/ ①iPhone的设计尺寸 iPhone界面尺寸: 设备 分辨率 状态栏高度 导航栏高度 标签栏(工具栏)高度 iPhone6 plu ...
- iOS 生产证书 分类: ios相关 app相关 2015-05-22 14:49 175人阅读 评论(0) 收藏
首先登陆https://developer.apple.com(99美元账号) 选择iOS Developer program 板块下的 Certificates,Identifiers & ...
- 分页。php 引用代码
<?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $lis ...
- hisi出的H264码流结构
hisi出的H264码流结构: IDR帧结构如下: 开始码 + nalu + I帧 + 开始码 + nalu + SPS + 开始码 + nalu + PPS + ...
- SQL Select结果增加自增自段(网转)
http://www.cnblogs.com/haver/archive/2011/07/14/2106349.html/* 方法一*/ SELECT 序号= (SELECT COUNT(客户编号) ...