HDU - 1716 排列2 水题
排列2
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9583 Accepted Submission(s): 3485
现有四张卡片,用这四张卡片能排列出很多不同的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<stdio.h>
int a[4],i;
void sum(int num[],int x1, int x2, int x3, int x4)
{
num[i++] = a[x1] * 1000 + a[x2] * 100 + a[x3] * 10 + a[x4];
num[i++] = a[x1] * 1000 + a[x2] * 100 + a[x4] * 10 + a[x3];
num[i++] = a[x1] * 1000 + a[x3] * 100 + a[x2] * 10 + a[x4];
num[i++] = a[x1] * 1000 + a[x3] * 100 + a[x4] * 10 + a[x2];
num[i++] = a[x1] * 1000 + a[x4] * 100 + a[x2] * 10 + a[x3];
num[i++] = a[x1] * 1000 + a[x4] * 100 + a[x3] * 10 + a[x2];
}
int main()
{
int p = 0;
while (~scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]))
{
int num[24] = { 0 };
if (!a[0] && !a[1] && !a[2] && !a[3])
{
break;
}
if (p == 0)p = 1;
else printf("\n");
i = 0;
sum(num, 0, 1, 2, 3);
sum(num, 1, 2, 3, 0);
sum(num, 2, 3, 0, 1);
sum(num, 3, 0, 1, 2);
int temp,j;
for (i = 23; i >0; i--)
{
for (j = 0; j < i-1; j++)
{
if (num[j] > num[j + 1])
{
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
}
}
} for (i = 0; i < 23; i++)
{
//printf("%d ",num[i]);
if (num[i] != num[i + 1]&&num[i]>1000)
{
printf("%d", num[i]);
if (num[i] / 1000 != num[i + 1] / 1000)
{
printf("\n");
}
else
{
printf(" ");
}
}
}
printf("%d\n", num[i]);
}
return 0;
}
HDU - 1716 排列2 水题的更多相关文章
- hdu 1716 排列2(DFS搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Time Limit: 1000/1000 MS (Java/Others) Me ...
- hdu 1106:排序(水题,字符串处理 + 排序)
排序 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 4950 Monster (水题)
Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...
- HDU 4813 Hard Code 水题
Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDU 4593 H - Robot 水题
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDOJ/HDU 2560 Buildings(嗯~水题)
Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...
- HDOJ(HDU) 1859 最小长方形(水题、、)
Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...
- HDU—2021-发工资咯(水题,有点贪心的思想)
作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵 但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...
- hdu 4451 Dressing 排列组合/水题
Dressing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
随机推荐
- Metrics.Net实践(2)在WEB中应用度量
Gauges 可以画出Http Request执行时间的波形图: actionInfo表示MVC中的Action,即按照action类型来分组 Metric.Context(this.actionIn ...
- bzoj 2342 [Shoi2011]双倍回文(manacher,set)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题意] 求出形如w wR w wR的最长连续子串. [思路] 用manache ...
- 什么是EOF -- 转
转载地址:http://www.ruanyifeng.com/blog/2011/11/eof.html 我学习C语言的时候,遇到的一个问题就是EOF. 它是end of file的缩写,表示&quo ...
- vue dev开发环境跨域和build生产环境跨域问题解决
dev开发时解决请求跨域问题:config-index.js 配置代理dev: { env: require('./dev.env'), port: 8082, assetsSubDirectory: ...
- 状压dp(B - 炮兵阵地 POJ - 1185 )
题目链接:https://cn.vjudge.net/contest/276236#problem/B 题目大意:略 具体思路:和我的上一篇写状压dp的思路差不多,不过就是这个题相当于上一个题的升级 ...
- 解决 Electron 包下载太慢问题
项目下新建 .npmrc 文件,加入如下配置: electron_mirror=https://npm.taobao.org/mirrors/electron/ 即使用淘宝的源,重新 npm inst ...
- Multiple HTTPS Bindings IIS 7 Using appcmd
http://toastergremlin.com/?p=308 Sometimes when using a wildcard SSL or Unified Communications Certi ...
- python基础--os模块和sys模块
os模块提供对操作系统进行调用的接口 # -*- coding:utf-8 -*-__author__ = 'shisanjun' import os print(os.getcwd())#获取当前工 ...
- No.1 selenium学习之路之浏览器操作
selenium基础,首先就是浏览器的相关操作 下面描述几种浏览器的常用操作 1.打开浏览器 webdriver后面添加想要打开的浏览器 Ie或者Chrome 2.打开指定页面(百度) 3.休眠时间 ...
- 洛谷P3396哈希冲突
传送门啦 非常神奇的分块大法. 这个题一看数据范围,觉得不小,但是如果我们以 $ \sqrt(x) $ 为界限,数据范围就降到了 $ x < 400 $ 我们设数组 $ f[i][j] $ 表示 ...