题目链接: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. Winform中checklistbox控件的常用方法

    Winform中checklistbox控件的常用方法最近用到checklistbox控件,在使用其过程中,收集了其相关的代码段1.添加项checkedListBox1.Items.Add(" ...

  2. Learning Roadmap of Deep Reinforcement Learning

    1. 知乎上关于DQN入门的系列文章 1.1 DQN 从入门到放弃 DQN 从入门到放弃1 DQN与增强学习 DQN 从入门到放弃2 增强学习与MDP DQN 从入门到放弃3 价值函数与Bellman ...

  3. kvm -- Kernel-based Virtual Machine

    1.虚拟机类型: 类型1 硬件上直接安装hp  类型2 硬件上安装HOST 上面跑VMM 2.kvm概要 kvm 不算类型1也不算类型二.两种特性都有,他是linux的一个内核模块,内核中本身没有hv ...

  4. Java后台传前台json数组

    function checkStore(){ var flag=1; $.ajax({ url:"widget?type=shop_cart&ajax=yes&action= ...

  5. iOS开发 贝塞尔曲线UIBezierPath

    最近项目中需要用到用贝塞尔曲线去绘制路径 ,然后往路径里面填充图片,找到这篇文章挺好,记录下来 自己学习! 转至 http://blog.csdn.net/guo_hongjun1611/articl ...

  6. 在腾讯云上创建您的SQL Cluster(4)

    版权声明:本文由李斯达原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/255 来源:腾云阁 https://www.qclo ...

  7. IntelliJ IDEA 修改包名

    1.首先将AndroidManifest的Package Name重命名(快捷键shift+F6或者右键Refctor然后Rename)这时Package Name就改变了,但是Src的文件名还没变2 ...

  8. Java过滤器,SpringMVC拦截器之间的一顺序点关系

    由于最近做的项目中有一部分是接口远程调用,用到了接入权限和业务权限的鉴定,需要采用SpringMVC的拦截器,以前用Struts2的时候用过拦截器,而SpringMVC的拦截器功能之前没研究过,所以这 ...

  9. JavaScipt的秘密花园

    对象使用和属性 JavaScript 中所有变量都可以当作对象使用,除了两个例外 null 和undefined. false.toString(); // 'false'[1, 2, 3].toSt ...

  10. leetcode算法思想快速一览

    整理了一下思路,想深入了解还得多去写,无奈时间紧迫的情况下抛砖引玉也不失为下策: 1.Two Sum Easy 给出一个数组,找出其中两个和为目标值的坐标.思路: [1]排序. 和为目标值,一般的思路 ...