STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:
HDU - 1716 Ray又对数字的列产生了兴趣:
现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
Input
每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。
Output
对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。
每组输出数据间空一行,最后一组数据后面没有空行。
Sample Input 1 2 3 4
1 1 2 3
0 1 2 3
0 0 0 0
Sample Output
1234 1243 1324 1342 1423 1432
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
思路,使用全排列next_permat 或通过一个不断排列组合用
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
set<int> mx;
int main()
{
int a[5];
int sb=0;
for(;;)
{
mx.clear();
int multi;
for(int i=1;i<5;i++)
{
cin>>a[i];
}
if(a[1]==0&&a[2]==0&&a[3]==0&&a[4]==0) break;
if(sb)cout<<endl;
sb++;
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
if(i==j) continue;
for(int k=1;k<5;k++)
{
if(j==k||i==k) continue;
for(int l=1;l<5;l++)
{
if(k==l||l==j||l==i) continue;
multi=a[i]*1000+a[j]*100+a[k]*10+a[l];
if(multi>999) mx.insert(multi);
}
}
}
}
set<int>::iterator poi,p2;
p2=mx.begin();
int xa=0;
for(poi=mx.begin();poi!=mx.end();poi++)
{
p2++;
if(xa) cout<<' ';
xa++;
cout<<*poi;
if(*p2/1000!=*poi/1000)
{
cout<<endl;
xa=0;
}
}
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
char a[4]={0};
int x=0;
for(;;)
{
for(int i=0;i<4;i++)
{
cin>>a[i];
}
sort(a,a+4);
char w=a[0];
if(a[0]=='0'&&a[1]=='0'&&a[3]=='0'&&a[2]=='0') break;
if(x) cout<<endl;
x++;
int qt=0;
int lasta0=-1;
bool flag2=true;
do {
if(a[0]=='0')continue;
if(flag2)flag2 = false;
else if(a[0] == lasta0) cout<<' ';
else cout<<endl;
cout<<a[0]<<a[1]<<a[2]<<a[3];
lasta0 = a[0];
} while(next_permutation(a, a +4));
cout<<endl;
}
return 0;
}
STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:的更多相关文章
- hdu 1716(dfs)
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Problem Description Ray又对数字的列产生了兴趣:现 ...
- hdu 1716 排列2(DFS搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Time Limit: 1000/1000 MS (Java/Others) Me ...
- (next_permutation) 排列2 hdu 1716
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 1716:排列2(全排列)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU - 1716 排列2 水题
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 1716 排列2
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 1716 排序2(dfs)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- 几道STL题目(FJUT - OJ STL训练1)
这个OJ一直在做,一些专题题目都很好,从易至难,阶梯上升,很适合像我这样的蒟蒻 =7= 这篇是关于其中一个专题训练的题解思路及代码 http://120.78.128.11/Contest.jsp ...
- HDU 1176 免费馅饼 (类似数字三角形的题,很经典,值得仔细理解的dp思维)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1176 免费馅饼 Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- MTK Android 设置-选择日期格式 [管理和组织首选项,ListPreference,CheckBoxPreference,EditTextPreference,RingtonePreference]
###android.preference.ListPreference的一些特性 android:key 选项的名称或键 android:title 选项的标题 android:summary ...
- MTK Android 预置APK
[FAQ03038] 如何预置APK [DESCRIPTION]1, 如何将带源码的 APK 预置进系统?2, 如何将无源码的APK预置进系统?3, 如何预制APK使得用户可以卸载?4, 如何使得用户 ...
- C语言 生日快乐
#include <stdio.h> #include <math.h> #include <stdlib.h> #define I 20 #define R 34 ...
- 【python实现卷积神经网络】卷积层Conv2D实现(带stride、padding)
关于卷积操作是如何进行的就不必多说了,结合代码一步一步来看卷积层是怎么实现的. 代码来源:https://github.com/eriklindernoren/ML-From-Scratch 先看一下 ...
- 10.6 IoStudentManager
package day11_io_student.student_demo; public class Student { private String id; private String name ...
- 两个div在同一行显示
栅格系统需要引用bootstrap插件 <script src="~/Scripts/BootStrap/bootstrap.js"> </script> ...
- mount --bind绑定命令
将目录或文件DirFile-1绑定到目录或文件DirFile-2上,所有对DirFile-2的访问就是对DirFile-1的访问 mount --bind [DirFile-1] [DirFile-2 ...
- EFCore.Sharding(EFCore开源分表框架)
EFCore.Sharding(EFCore开源分表框架) 简介 引言 开始 准备 配置 使用 按时间自动分表 性能测试 其它简单操作(非Sharing) 总结 简介 本框架旨在为EF Core提供S ...
- 高德APP启动耗时剖析与优化实践(iOS篇)
前言最近高德地图APP完成了一次启动优化专项,超预期将双端启动的耗时都降低了65%以上,iOS在iPhone7上速度达到了400毫秒以内.就像产品们用后说的,快到不习惯.算一下每天为用户省下的时间,还 ...
- ORA-0245
经常有客户报错ORA-0245 1.11.2 rac环境, rman存在snap控制文件路径,默认是文件系统[非共享,导致备份控制文件报错] 解决方法:将snap路径配置到ASM磁盘组共享路径[nfs ...