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了。一脸懵逼。

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

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

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 14
#define M 100004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
LL e[N];
LL mi[N][N],c[N][M],d[N][M];
bool cmp(int a,int b)
{
return a<b;
}
void init()
{
int i,j;
for(e[]=,i=;i<;i++)e[i]=e[i-]*;
for(i=;i<;i++)
{
mi[i][]=;
for(j=;j<;j++)mi[i][j]=mi[i][j-]*i;
}
for(j=;j<;j++)
{
for(i=;i<e[];i++)
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[],
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;
sort(c[j],c[j]+e[],cmp);
sort(d[j],d[j]+e[],cmp);
}
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
printf("Case #%d: ",cass);
ans=;
scanf("%d%d",&n,&m);
for(i=,j=e[]-;i<e[] && j;)
{
if(c[m][i]+d[m][j]>n)j--;
else if(c[m][i]+d[m][j]<n)i++;
else
{
x=y=;
while(c[m][++i]==c[m][i-] && i<e[])x++;
while(d[m][--j]==d[m][j+] && j)y++;
ans+=x*y;
}
}
printf("%d\n",ans-(n==));
}
return ;
}
/*
// //
*/

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. iOS imagePicker使用方法,方便使用!三步轻松搞定!

    自己总结的修改头像的方法,只为方便自己查询使用!转发 步骤:1.遵守代理协议 <UIImagePickerControllerDelegate,UINavigationControllerDel ...

  2. mac最常用终端命令

    1分钟,快速复习下: pwd (显示当前所在路径) ls -l  (列出文件的详细信息,如创建者,创建时间,文件的读写权限列表等等) touch `filename`(创建文件) open `file ...

  3. 00_ForTest

    -----该页是爬虫的测试页请忽略------- 1234545@qq.comadasdsdasdsad阿打算多少其热情为 asdasdasdasd4w5wsdvv啊实打实大 啊实打实大asdasda ...

  4. HDU 1175 连连看(BFS)

    连连看 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  5. HDU_2014 青年歌手大奖赛_评委会打分

    Problem Description 青年歌手大奖赛中,评委会给参赛选手打分.选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分.   Input 输入数据有多组,每 ...

  6. ubuntu logout 命令

    gnome-session-quit 点击打开链接http://askubuntu.com/questions/15795/how-can-you-log-out-via-the-terminal

  7. C# Linq To DataTable 分组统计 DEMO

    DataTable dt = SQLLayer.Get工作量统计(beginDate, endDate);             var querySum = from t in dt.AsEnum ...

  8. 在Linux下不使用密码远程登陆其他Linux

    有时需要再一台Linux上登陆其他Linux服务器,通常可以直接使用SSH命令,加入两台服务器一台服务器A,IP地址192.168.1.2,另一台服务器B,IP地址192.168.1.3,如果想从A服 ...

  9. kindeditor编辑器代码过滤解决方法.

    很多朋友在使用Kindeditor编辑器的时候都会遇到这样一个问题,如:给A标签加上title属性过后,浏览的时候,却神奇般地发现title属性没有了.再次切换html源代码的时候,返现编辑器将tit ...

  10. luarocks在macOS系统上的安装

    luarocks是基于lua开发的一个包管理工具,所以在安装luarocks之前需要先安装lua(见博客同目录下“lua在MacOS系统上的安装”).具体的安装步骤如下: 1.源码安装部署luaroc ...