HDU5936-Difference
来源:互联网 发布:网络运营经理岗位职责 编辑:程序博客网 时间:2024/06/14 17:46
Difference
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 850 Accepted Submission(s): 236
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 remembersK , x and forgets y . please help him find how many y satisfy x=f(y,K)−y .
then he gets the result
As Ruins is forgetful, a few seconds later, he only remembers
Input
First line contains an integer T , which indicates the number of test cases.
Every test case contains one line with two integersx , K .
Limits
1≤T≤100
0≤x≤109
1≤K≤9
Every test case contains one line with two integers
Limits
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
22 23 2
Sample Output
Case #1: 1Case #2: 2
Source
2016年中国大学生程序设计竞赛(杭州)
题意:给你数字x和k,问有多少个数字满足它每位数字k次方的和等于x和它的和
解题思路:可以用折半搜索的方法,先预处理出0~100000所有数每位数字k次方的和,然后先枚举前5位,记下相应的值,二分查找后5位,与前面的匹配看是否能够凑成x,最后统计答案。(本题x等于0时,因为题目y要求大于0,所以答案要建一)
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <map>#include <set>using namespace std;#define LL long longconst int INF=0x3f3f3f3f;struct node{ LL sum1,sum2;} a[10][100005];LL mypow(int x,int y){ LL ans=1; for(int i=1; i<=y; i++) ans*=1LL*x; return ans;}bool cmp(const node a,const node b){ return a.sum2<b.sum2;}int main(){ memset(a,0,sizeof a); for(int i=0; i<100000; i++) { int k=i; for(int j=1; j<=9; j++) a[j][i].sum1-=1LL*100000*i,a[j][i].sum2-=1LL*i; while(k>0) { LL kk=k%10; LL x=kk; for(int j=1; j<=9; j++) { a[j][i].sum1+=x; a[j][i].sum2+=x; x*=kk; } k/=10; } } for(int i=1; i<=9; i++) sort(a[i],a[i]+100000,cmp); int kkk,t,cas=0; LL x; scanf("%d",&t); while(t--) { printf("Case #%d: ",++cas); scanf("%lld%d",&x,&kkk); LL cnt=0; for(int i=0; i<100000; i++) { LL xx=x-a[kkk][i].sum1; int l=0,r=99999,ans1=-1,ans2=-1; while(l<=r) { int mid=(l+r)>>1; if(a[kkk][mid].sum2>xx) r=mid-1; else if(a[kkk][mid].sum2<xx) l=mid+1; else ans1=mid,r=mid-1; } if(ans1==-1) continue; l=0,r=99999; while(l<=r) { int mid=(l+r)>>1; if(a[kkk][mid].sum2>xx) r=mid-1; else if(a[kkk][mid].sum2<xx) l=mid+1; else ans2=mid,l=mid+1; } cnt+=1LL*(ans2-ans1+1); } if(x==0) cnt--; printf("%lld\n",cnt); } return 0;}
阅读全文
0 0
- HDU5936-Difference
- 枚举--hdu5936 difference
- HDU5936 Difference 【中途相遇法】
- Difference (hdu5936——2016ccpc杭州站D题)
- hdu5936二分
- HDU5936折半枚举+思维
- ccpc2016杭州D题HDU5936
- DB-difference
- Difference Equation
- Date Difference
- adjacent difference
- Expected Difference
- Smallest Difference
- difference hash
- Smallest Difference
- Smallest Difference
- Smallest Difference
- Difference Row
- SpringBoot非官方教程 | 第二十四篇: springboot整合docker
- huffman树的应用——文件压缩
- 最快发表速度
- JavaScript中Number对象的方法和Math对象的方法
- SpringBoot非官方教程 | 第二十五篇:2小时学会springboot
- HDU5936-Difference
- 关于自定义Dialog那些事
- SpringBoot非官方教程 | 第十六篇:用restTemplate消费服务
- Python enumerate函数无法顺序遍历字典
- CUDA Samples:Vector Add
- c语言返回局部变量
- SpringBoot非官方教程 | 第十五篇:Springboot整合RabbitMQ
- Linux作为服务端,Windows作为客户端socket通信
- Java动态代理之cglib