HDU2274-Magic WisKey
来源:互联网 发布:梦幻花园无法加载 网络 编辑:程序博客网 时间:2024/04/30 18:00
Magic WisKey
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 583 Accepted Submission(s): 329
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.
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.
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
293326663922174245386
Sample Output
000380771921238
Source
HDU 8th Programming Contest Site(1)
题意: 选定五个数字,他们形成一个五位数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。
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <set>#include <map>using namespace std;int n;int main(){ int a[100005]; for(int i=0;i<=99999;i++) { int sum=0; int n=i; while(n>0) { sum+=n%10; n/=10; } int ans=sum*24*11111; a[i]=ans-i; } while(~scanf("%d",&n)) { for(int i=0;i<99999;i++) { if(a[i]==n) printf("%05d\n",i); } } return 0;}
0 0
- HDU2274-Magic WisKey
- HDU 2274 Magic WisKey
- HDU-2274 Magic Wiskey
- 【magic】
- magic
- Magic
- magic
- WisKey的眼神
- hdu1577 WisKey的眼神
- Wiskey's Power+数学题
- HDU1577 WisKey的眼神
- wiskey的眼神
- WisKey的眼神 HDU
- hdu---1577WisKey的眼神
- HDU:1577 WisKey的眼神
- hdu 1577 WisKey的眼神
- WisKey的眼神(GCD)
- hdu 2603 && 比赛 D - Wiskey's Power
- stm8L051使用库建工程(暂记录)
- 【pycharm 教程】(一)安装和首次使用
- Android支持库中Fragment的使用及参数传递
- ArchLinux-- OpenStreetMap瓦片服务器的新宿主
- BZOJ 1191: [HNOI2006]超级英雄Hero
- HDU2274-Magic WisKey
- 数字构图
- 数据库的乐观锁和悲观锁
- 代码去除标题和状态栏
- 【c++】处理语句
- 【Pycharm教程】(二)设置字体大小
- pat-bl-1033
- 上下文3种
- 问题 D: 士兵排阵(中位数:贪心思想)