HDU 2274 Magic WisKey

16 篇文章 0 订阅
2 篇文章 0 订阅

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。


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



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值