排列2

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 6383    Accepted Submission(s): 2461

Problem Description
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
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  1715 1717 2097 1521 1112 
输出格式比较坑
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int vis[100000+10];
int main()
{
int num[5];
int t=0;
while(scanf("%d%d%d%d",&num[0],&num[1],&num[2],&num[3])!=EOF)
{
memset(vis,0,sizeof(vis));
sort(num,num+4);
if(num[3]+num[1]+num[2]+num[0]==0) break; if(t!=0) printf("\n");t++;
if(num[0]==num[1]&&num[0]==num[2]&&num[0]==num[3])
{
printf("%d%d%d%d\n",num[0],num[0],num[0],num[0]);
continue;
}
for(int i=0;i<4;i++)
{
if(num[i]==0) continue;
int f=false;
int a[10];
memset(a,0,sizeof(a));
int cnt=0;
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
if(i==j||i==k||i==l||
j==k||j==l
||k==l)
continue;
int ans=num[i]*1000+num[j]*100+num[k]*10+num[l];
if(vis[ans]) continue;
if(!vis[ans])
{
a[cnt++]=ans;
vis[ans]=1;
} }
}
}
if(cnt>=1)
{
printf("%d",a[0]);
for(int i=1;i<cnt;i++)
printf(" %d",a[i]);
printf("\n");
}
}
// printf("\n");
}
return 0;
}

hdoj--1716--排列2(暴力水题)的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. [Usaco2008 Feb]Line连线游戏[暴力][水题]

    Description Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i ...

  3. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  4. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  5. UOJ #278. 【UTR #2】题目排列顺序(排序水题)

    #278. [UTR #2]题目排列顺序 丢个传送门:http://uoj.ac/problem/278 描述 “又要出题了.” 宇宙出题中心主任 —— 吉米多出题斯基,坐在办公桌前策划即将到来的 U ...

  6. HDOJ 1716 排列2 next_permutation函数

    Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡 ...

  7. HDOJ 1716 排列2(next_permutation函数)

    Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数. Input 每组数据占一行,代表四张卡 ...

  8. 求先序排列(NOIP2001&NOIP水题测试(2017082301))

    题目链接:求先序排列 这道题讲白了,就是数的构造,然后遍历. 思路大致是这样: 我们先通过后序遍历,找到当前区间的根,然后在中序遍历中找到根对应的下标,然后就可以分出左右子树,建立当前根与左右子树根的 ...

  9. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. Linux部署Web项目小记

    1.安装Tomcat 官网下载 解压缩:tar -zxvf apache-tomcat-8.0.32.tar.gz 配置server.xml 连接池: <Executor name=" ...

  2. 90-Standard Deviation 标准离差指标.(2015.7.4)

    Standard Deviation 标准离差指标 ~计算: StdDev = SQRT (SUM (CLOSE - SMA (CLOSE, N), N)^2)/N 注解: SQRT - 正方体根: ...

  3. 集训第五周动态规划 E题 LIS

    Description The world financial crisis is quite a subject. Some people are more relaxed while others ...

  4. AutoMapper 使用总结1

    初识AutoMapper 在开始本篇文章之前,先来思考一个问题:一个项目分多层架构,如显示层.业务逻辑层.服务层.数据访问层.层与层访问需要数据载体,也就是类.如果多层通用一个类,一则会暴露出每层的字 ...

  5. Arctic Network POJ - 2349

    The Department of National Defence (DND) wishes to connect several northern outposts by a wireless n ...

  6. node+mongodb+win7

    一.安装mongodb,参照教程,注意要先启动mongod.exe,再启动mongd.exe.

  7. 一个1x1px大小Data/Base64数据的gif透明图片

    <img src="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNg ...

  8. spring mvc 访问静态资源404

    访问比如css js出现404提示 在spring的配置文件中加上如下代码即可 <!-- 静态资源404 --> <mvc:resources location="/res ...

  9. Effective C++ Item 41 了解隐式接口和编译期多态

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:class 和 templates 都支持接口和多态. 对 classes 而言接口是 ...

  10. imx6q GPIO功能的用法

    假如我们要使用扩展口的第11脚EIM_D18. 先在arch/arm/plat-mxc/include/mach/iomux-mx6q.h中找有EIM_18. 能够找到MX6Q_PAD_EIM_D18 ...