ACM学习历程—HDU1716 排列2(dfs && set容器)
Description
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
Input
Output
每组输出数据间空一行,最后一组数据后面没有空行。
Sample Input
Sample Output
题目要求的就是四个数全排列从小到大输出。
由于考虑到需要排序,而且要去重,所以直接使用了set容器。
全排列用dfs生成。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#define LL long long using namespace std; int a[];
bool vis[];
set <int> ans; void dfs(int now, int val)
{
if (now == )
{
if (val >= )
ans.insert(val);
return;
}
for (int i = ; i < ; ++i)
{
if (vis[i])
continue;
vis[i] = true;
dfs(now+, val*+a[i]);
vis[i] = false;
}
} void Work()
{
ans.clear();
memset(vis, , sizeof(vis));
dfs(, );
set <int>::iterator it;
int high = -;
bool flag = false;
for (it = ans.begin(); it != ans.end(); ++it)
{
if (high == -)
high = *it/;
if (high != - && *it/ != high)
{
printf("\n");
high = *it/;
flag = false;
}
if (flag)
printf(" ");
printf("%d", *it);
flag = true;
}
printf("\n");
} int main()
{
//freopen("test.in", "r", stdin);
bool flag = false;
while (scanf("%d%d%d%d", &a[], &a[], &a[], &a[]) != EOF &&
(a[]+a[]+a[]+a[]))
{
if (flag)
printf("\n");
Work();
flag = true;
}
return ;
}
ACM学习历程—HDU1716 排列2(dfs && set容器)的更多相关文章
- ACM学习历程—BZOJ 2115 Xor(dfs && 独立回路 && xor高斯消元)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题目大意是求一条从1到n的路径,使得路径xor和最大. 可以发现想枚举1到n的所有路 ...
- ACM学习历程—UESTC 1219 Ba Gua Zhen(dfs && 独立回路 && xor高斯消元)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1219 题目大意是给了一张图,然后要求一个点通过路径回到这个点,使得xor和最大. 这是CCPC南阳站的一道题 ...
- ACM学习历程—SNNUOJ1215 矩阵2(二分 && dfs)
http://219.244.176.199/JudgeOnline/problem.php?id=1215 这是这次微软和百度实习面试的一道题,题目大意就是:有一个n*m的矩阵,已知它每一行都是不严 ...
- ACM学习历程—Hihocoder 1291 Building in Sandbox(dfs && 离线 && 并查集)
http://hihocoder.com/problemset/problem/1291 前几天比较忙,这次来补一下微软笔试的最后一题,这题是这次微软笔试的第四题,过的人比较少,我当时在调试B题,没时 ...
- ACM学习历程—HDU5269 ZYB loves Xor I(位运算 && dfs && 排序)(BestCoder Round #44 1002题)
Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he ...
- ACM学习历程—ZOJ 3861 Valid Pattern Lock(dfs)
Description Pattern lock security is generally used in Android handsets instead of a password. The p ...
- ACM学习历程——HDU5202 Rikka with string(dfs,回文字符串)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- ACM学习历程—BestCoder Round #75
1001:King's Cake(数论) http://acm.hdu.edu.cn/showproblem.php?pid=5640 这题有点辗转相除的意思.基本没有什么坑点. 代码: #inclu ...
随机推荐
- scikit-learn(project中用的相对较多的模型介绍):2.3. Clustering(可用于特征的无监督降维)
參考:http://scikit-learn.org/stable/modules/clustering.html 在实际项目中,我们真的非常少用到那些简单的模型,比方LR.kNN.NB等.尽管经典, ...
- Spring Cloud Zuul API服务网关之请求路由
目录 一.Zuul 介绍 二.构建Spring Cloud Zuul网关 构建网关 请求路由 请求过滤 三.路由详解 一.Zuul 介绍 通过前几篇文章的介绍,我们了解了Spring Cloud ...
- anaconda3.5 3.6 2.7
https://repo.continuum.io/archive/ Filename Size Last Modified MD5 Anaconda2-5.0.1-Linux-x86.sh 413. ...
- Multicast注册中心
1 2 3 4 提供方启动时广播自己的地址. 消费方启动时广播订阅请求. 提供方收到订阅请求时,单播自己的地址给订阅者,如果设置了unicast=false,则广播给订阅者. 消费方收到提供方地址时, ...
- 把对象写入Postgresql中
工作中,遇到把大对象写入Postgresql数据库中 package com.geni_sage.gdme.cws.dic; import java.io.BufferedInputStream; i ...
- MySQL5.7.18 备份、Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份,数据导入导出
粗略介绍冷备,热备,温暖,及Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份 --备份的目的 灾难恢复:意外情况下(如服务器宕机.磁盘损坏等)对损 ...
- 编译webrtc for android库与apk
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git export PATH=`pwd`/depot_t ...
- TP 框架 如果去掉表前缀
#jd_admin_abc 去掉前缀 C('DB_PREFIX')=获取前缀 结果为admin_abc $table_Name=str_replace(C('DB_PREFIX'), '', $tab ...
- DBUtils使用详解
https://blog.csdn.net/samjustin1/article/details/52220423 https://www.cnblogs.com/CQY1183344265/p/58 ...
- Python中的注解“@” 、Java 注解
https://blog.csdn.net/u013474436/article/details/75675113 https://blog.csdn.net/briblue/article/deta ...