Difference

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

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
 
Source
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5947 5946 5945 5944 5942 
 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5936

题目大意:

  (y每位上的数字的K次幂之和)

  X=f(y,K)-y。现在给定X和K,求有多少Y满足题意。

  数据范围 

题目思路:

  【中途相遇法】

  数据范围x在[0,109],y的位数不会超过10位。

  所以想直接对半分,先枚举前5位,记下相应的值,再枚举后5位,与前面的匹配看是否能够凑成x,最后统计答案即可。

  一开始用map写,T了。一脸懵逼。

  后来改成将每个出现的值都记下来,排序,正反扫一遍。。过了。

  可以预处理一些操作、运算。

  1. //
  2. //by coolxxx
  3. //#include<bits/stdc++.h>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<string>
  7. #include<iomanip>
  8. #include<map>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #include<bitset>
  13. #include<memory.h>
  14. #include<time.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17. #include<string.h>
  18. //#include<stdbool.h>
  19. #include<math.h>
  20. #pragma comment(linker,"/STACK:1024000000,1024000000")
  21. #define min(a,b) ((a)<(b)?(a):(b))
  22. #define max(a,b) ((a)>(b)?(a):(b))
  23. #define abs(a) ((a)>0?(a):(-(a)))
  24. #define lowbit(a) (a&(-a))
  25. #define sqr(a) ((a)*(a))
  26. #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
  27. #define mem(a,b) memset(a,b,sizeof(a))
  28. #define eps (1e-8)
  29. #define J 10000
  30. #define mod 1000000007
  31. #define MAX 0x7f7f7f7f
  32. #define PI 3.14159265358979323
  33. #define N 14
  34. #define M 100004
  35. using namespace std;
  36. typedef long long LL;
  37. double anss;
  38. LL aans;
  39. int cas,cass;
  40. int n,m,lll,ans;
  41. LL e[N];
  42. LL mi[N][N],c[N][M],d[N][M];
  43. bool cmp(int a,int b)
  44. {
  45. return a<b;
  46. }
  47. void init()
  48. {
  49. int i,j;
  50. for(e[]=,i=;i<;i++)e[i]=e[i-]*;
  51. for(i=;i<;i++)
  52. {
  53. mi[i][]=;
  54. for(j=;j<;j++)mi[i][j]=mi[i][j-]*i;
  55. }
  56. for(j=;j<;j++)
  57. {
  58. for(i=;i<e[];i++)
  59. c[j][i]=mi[i/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]][j]-i*e[],
  60. d[j][i]=mi[i/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]][j]-i;
  61. sort(c[j],c[j]+e[],cmp);
  62. sort(d[j],d[j]+e[],cmp);
  63. }
  64. }
  65. int main()
  66. {
  67. #ifndef ONLINE_JUDGE
  68. // freopen("1.txt","r",stdin);
  69. // freopen("2.txt","w",stdout);
  70. #endif
  71. int i,j,k;
  72. int x,y,z;
  73. init();
  74. // for(scanf("%d",&cass);cass;cass--)
  75. for(scanf("%d",&cas),cass=;cass<=cas;cass++)
  76. // while(~scanf("%s",s))
  77. // while(~scanf("%d%d",&n,&m))
  78. {
  79. printf("Case #%d: ",cass);
  80. ans=;
  81. scanf("%d%d",&n,&m);
  82. for(i=,j=e[]-;i<e[] && j;)
  83. {
  84. if(c[m][i]+d[m][j]>n)j--;
  85. else if(c[m][i]+d[m][j]<n)i++;
  86. else
  87. {
  88. x=y=;
  89. while(c[m][++i]==c[m][i-] && i<e[])x++;
  90. while(d[m][--j]==d[m][j+] && j)y++;
  91. ans+=x*y;
  92. }
  93. }
  94. printf("%d\n",ans-(n==));
  95. }
  96. return ;
  97. }
  98. /*
  99. //
  100.  
  101. //
  102. */

HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))的更多相关文章

  1. HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))

    朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...

  2. HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

  3. HDU 6273.Master of GCD-差分数组 (2017中国大学生程序设计竞赛-杭州站-重现赛(感谢浙江理工))

    Super-palindrome 题面地址:http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 这道题是差分数组的题目,线 ...

  4. HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  5. HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)

    异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

  6. HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

  7. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))

    Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. 如何在Angular2中使用jquery

    首先在index.html中引入jquery文件 <script src="http://cdn.bootcss.com/jquery/2.1.3/jquery.js"> ...

  2. c语言中继承和多态的简单实现

    C语言本身是不支持继承和多态的,但其实在 C 的世界里,有一套非常有名的面向对象的框架,用的也非常广,那就是 GObject,它是整个图形界面开发库 GTK 的基石,在IBM developerWor ...

  3. Java进程CPU使用率高排查

    Java进程CPU使用率高排查 生产java应用,CPU使用率一直很高,经常达到100%,通过以下步骤完美解决,分享一下.1.jps 获取Java进程的PID.2.jstack pid >> ...

  4. Python中 if __name__ == '__main__': 详解

    一个python文件就可以看作是一个python的模块,这个python模块(.py文件)有两种使用方式:直接运行和作为模块被其他模块调用. __name__:每一个模块都有一个内置属性__name_ ...

  5. 网站开发常用jQuery插件总结(15)上传插件blueimp

    在介绍这个插件之前,先吐槽一下.这个插件功能很强大.带有的功能有:上传(单个文件或批量文件),自动上传或点击按钮上传,上传前缩略图显示,判断文件格式,上传前的文件操作,上传时进度条显示等功能.如果你用 ...

  6. PHP trim去空格函数

    trim() 能除去的字符有“ ”空格."\t"水平制表符."\n"换行符."\r"回车符."\0字符串结束符".&qu ...

  7. php计算最后一次,第一次字符串出现位置

    strpos($str, n) 首次,n在str第一次出现位置, strrpos($str, n) 最后一次,n在str最后一次出现位置 strripos区分大小写

  8. phpcms V9 首页模板文件解析(转)

    转自:http://www.cnblogs.com/Braveliu/p/5100018.html 转在了解了<phpcms V9 URL访问解析>之后,我们已经知道首页最终执行的是con ...

  9. 经典的C程序

    程序一:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数 #include<stdio.h> void main(){ int a, b, c, i; ; ...

  10. H5 required 改变错误提示oninvalid、oninput、onforminput

    <input type="text" name="password" oninvalid="this.setCustomValidity('XX ...