[原创]HDU 5936 Difference [思维啊]【思维】

2017-03-25 16:34:26 Tabris_ 阅读数:551


博客爬取于2020-06-14 22:41:07
以下为正文

版权声明:本文为Tabris原创文章,未经博主允许不得私自转载。
https://blog.csdn.net/qq_33184171/article/details/65937719


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

————————————————————————————————————————————
Difference

Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 733 Accepted Submission(s): 192

Problem Description
Little Ruins is playing a number game, first he chooses two positive integers y and K and calculates f(y,K), here

f(y,K)=z in every digits of yzK(f(233,2)=22+32+32=22)f(y,K)=∑_{z\ in\ every\ digits\ of\ y}z^K(f(233,2)=2^2+3^2+3^2=22)

then he gets the result

x=f(y,K)yx=f(y,K)−y

As Ruins is forgetful, a few seconds later, he only remembers K, x and forgets y. please help him find how many y satisfy x=f(y,K)y\ x=f(y,K)−y.

Input
First line contains an integer T, which indicates the number of test cases.

Every test case contains one line with two integers x, K.

Limits
1≤T≤100
0≤x≤109
1≤K≤9

Output
For every test case, you should output ‘Case #x: y’, where x indicates the case number and counts from 1 and y is the result.

Sample Input
2
2 2
3 2

Sample Output
Case #1: 1
Case #2: 2

————————————————————————————————————————————

题目大意:
就是给你k,x,问y的可能数

解题思路:
首先看到这个题实在没有好的想法,后发现,f(y,k)f(y,k)最大也不过f(999999999,9)f(999999999,9),这样也才不到10位,
但是即使这样 还是不太好找 后想到将这10位分成前5位和后5位,预处理出来然后就行匹配,

这个匹配我们有很多种方法搞了,
首先在预处理的时候进行排序,在前5位时注意要 $f(y,k)-y*100000\ $ 后5位$f(y,k)-y\ $即可

那么就是找两集合的元素加和为x的方案数了,

可以枚举一个来二分另一个, $ O(100000\log(100000))\ $
也可以对一个从前找,另一个从后找,(双指针法) $O(100000*2)\ $

代码注意细节就好