题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2274

Magic WisKey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 568    Accepted Submission(s):
323

Problem Description
On New Year Festival, Liu Qian’s magic impressed on
little WisKey’s heart and he wants to learn some magic to make himself
stronger.
  One day, he met a cowman named LinLe. Linle is very nice, he told
little WisKey the mysteries of magic. Now, little WisKey began to perform the
magic to you.
  “Hello, Everybody. I have five decimal numbers named a, b, c,
d, e, (0 <= a, b, c, d, e <= 9) and I rearranged them, and then combined
them into a number, for example <a, b, c, d, e> = a*10000 + b*1000 + c*100
+ d*10 + e*1. You know the number of permutations is 5! = 120. So you have 120
numbers in your hands, you can pick a number N from the 120 numbers and
calculate the sum S of remain 119 numbers. AHA~, If you tell me the S, I can
guess the N~!”
  It’s easy? Okay, you can challenge this.

 
Input
Each line will contain an integer S. Process to end of
file.
 
Output
For each case, output all possible N, print the number
N with 5 digits, including the leading zeros, one line per case.
I promise
every case have one solution at least. If have many N, please output them from
small to large in one line, separate them with a blank space.

 
Sample Input
2933266
6392217
4245386
 
Sample Output
00038
07719
21238
 
题目大意:选定五个数字,他们形成一个五位数N。你事先不知道是哪五个数字,但你知道这五个数字全排列后组成的 120 个五位数的和减去该五位数的结果S,求N。
 
解题思路:五位数总共的可能就是从00000~99999。所以先打表暴力枚举求出所有五位数的S,然后对于每个输入的S,查找对应的N。

求五位数全排列之和的方法:假设五个数字分别是a,b,c,d,e。首先考虑a,a在万位上会出现4!次,千位上也会出现4!次,百位十位个位同理,所以a出现的每个地方总和为a*4!*(10000+1000+100+10+1)。b,c,d,e与a类似。所以总和为(a+b+c+d+e)*4!*11111。

AC代码:

 #include<stdio.h>
#include<string.h>
int a[],s[],sum;
int main()
{
for(int i=;i<=;i++) { //先打表
int t=i,k=,sum;
while(t>) {
a[k++]=t%;
t/=;
}
int tmp=;
for(int j=;j<k;j++)
tmp+=a[j];
s[i]=tmp**-i;
}
while(~scanf("%d",&sum)) { //直接查询
for(int i=;i<=;i++)
if(sum==s[i]) printf("%05d\n",i);
}
return ;
}

HDU 2274 Magic WisKey的更多相关文章

  1. HDU 1153 magic bitstrings(读题+)

    hdu 1153 magic bitstrings 题目大意 一个质数p,现在让你求一个p-1长度的“01魔法串”.关于这个魔法串是这么定义的:     我们现在把这个串经过一段处理变成一个长宽均为p ...

  2. hdu 4605 Magic Ball Game

    http://acm.hdu.edu.cn/showproblem.php?pid=4605 可以离线求解 把所以可能出现的 magic ball  放在一个数组里(去重),从小到大排列 先不考虑特殊 ...

  3. [搜索] hdu 4016 Magic Bitwise And Operation

    主题链接: http://acm.hdu.edu.cn/showproblem.php?pid=4016 Magic Bitwise And Operation Time Limit: 6000/30 ...

  4. hdu A Magic Lamp

    http://acm.hdu.edu.cn/showproblem.php?pid=3183 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)   ...

  5. HDU 4605 Magic Ball Game(可持续化线段树,树状数组,离散化)

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. HDU 4602 Magic Ball Game(离线处理,树状数组,dfs)

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. 【树形动规】HDU 5834 Magic boy Bi Luo with his excited tree

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5834 题目大意: 一棵N个点的有根树,每个节点有价值ci,每条树边有费用di,节点的值只能取一次,边 ...

  8. HDU 4605 Magic Ball Game (在线主席树|| 离线 线段树)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一棵二叉树,每个结点孩子数目为0或者2. ...

  9. HDU 4323 Magic Number(编辑距离DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4323 题意: 给出n个串和m次询问,每个询问给出一个串和改变次数上限,在不超过这个上限的情况下,n个串中有多少个 ...

随机推荐

  1. WebClient上传音频文件

    //WebClient上传音频文件 public string UploadVoice(string fileNamePath) { Voice model=new Voice(); string s ...

  2. [Prodinner项目]学习分享_第三部分_Service层(业务逻辑层)

    前两节讲到怎样生成一个Model和怎样将Model映射到数据库,这一节将讲到业务逻辑层,也就是Service层. 1.Prodinner架构已经构建好的,基本的增删改查. 假设,我现在想操作第二节中讲 ...

  3. Apache—DBUtils框架

    1.所需要jar包 commons-collections-2.1.1.jarmchange-commons-java-0.2.11.jarmysql-connector-java-5.1.18-bi ...

  4. Linux 控制 配置 减少 交换分区 SWAP 虚拟内存使用

    对于某些大型应用来说,SWAP 严重影响性能,尽可能避免使用: The Linux kernel provides a tweakable setting that controls how ofte ...

  5. MUMmer 3使用方法

    DNA和核苷酸的快速比对软件包,基于suffix tree 数据结构,快速.图形化.模块可用于其他软件.可进行大基因组比对.多对多基因组比对. The MUMmer Home Page The MUM ...

  6. 23.APR/Native

    Apache Portable Runtime (APR) based Native library for Tomcat Table of Contents Introduction Install ...

  7. 习题-任务2初始ASP.NET MVC项目开发

    一.选择题 1.在ASP.NET MVC项目的RouteConfig.cs文件中,(    )方法注册了默认的路由配置. A.RegisterMap    B.RegisterRoutes    C. ...

  8. 0512 Scrum 项目3.0

    SCRUM 流程的步骤2: Spring 计划 1. 确保product backlog井然有序.(参考示例图1) 2. Sprint周期,一个冲刺周期,长度定为两周,本学期还有三个冲刺周期. 3. ...

  9. cookie预:

    什么是cookie? cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie.你可以使用 JavaScript 来创建和取回 cookie ...

  10. ioS基础篇(十九)——UIResponder简析

    UIResponder类定义了对象相应和控制事件的接口,他是UIApplication.UIView的超类,这类的实例通常被称为应答对象. 一.Responder对象 在iOS系统中,能够响应并处理事 ...