题目链接: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. BW常用事务码Tcode

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. php : 获取对象的属性名

    方案有多种: 一. 使用 get_object_vars() 方法 缺点: 只能显示 public 的 //只显示public的 var_dump(get_object_vars($test)); 处 ...

  3. 常用webservice接口

    商业和贸易: 1.股票行情数据 WEB 服务(支持香港.深圳.上海基金.债券和股票:支持多股票同时查询) Endpoint: http://webservice.webxml.com.cn/WebSe ...

  4. union (共用声明和共用一变量定义)

    "联合"是一种特殊的类,也是一种构造类型的数据结构.在一个"联合"内可以定义多种不同的数据类型, 一个被说明为该"联合"类型的变量中,允许装 ...

  5. 【xsy1019】小A的树论

    题意 三种操作: ①区间增值 ②某一个点换父亲 ③求子树和 \(1\leq n\leq 100000\) 分析 Splay维护dfn序. 小结 (1)使用Splay,通常要在Splay的两端各添加一个 ...

  6. ubuntu上mysql服务器安装后只能本地连接不能远程连接的问题

    安装好mysql后,想使用另一个电脑进行远程登录,在登录时 提示拒绝连接 百度后,发现需要两个步骤解决该问题 /etc/mysql/my.cnf 里修改bind_address = 0.0.0.0  ...

  7. Windows 10:解决开机显示C:\WINDOWS\system32\config\systemprofile\Desktop不可用的方法

      开机显示C:\WINDOWS\system32\config\systemprofile\Desktop不可用应该是不少网友都遇到过. 近日在使用Windows 10 Build 9926中,也出 ...

  8. WPF:换肤

    看了一篇博客,觉得样式很好看,就自己动手做了一下,做个总结. 效果:    选择不同的图片背景就会改变: 直接上代码: 每个Theme对应一张图,除了图的名称不同之外,Theme?.xaml中的内容相 ...

  9. easy ui datagrid 中getSelections方法只能获取一行数据

    解决方案:设置  idField : "", // 设置标识

  10. 回车键转tab键解决方案一

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...