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

66 篇文章 0 订阅

题目链接: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)

then he gets the result

x=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 .

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(999999999,9) ,这样也才不到10位,
但是即使这样 还是不太好找 后想到将这10位分成前5位和后5位,预处理出来然后就行匹配,

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

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

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

代码注意细节就好

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值