数学题好难啊!!!!

最长长度不超过十位, 折半枚举。。。

题解

 #include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int>> using namespace std; const int N = 1e5 + ;
const int M = 1e4 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL base = ;
const int mod = 1e9 + ; int x, k;
LL f[N][], v[N]; int fastPow(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = ans * a;
a = a * a; b >>= ;
}
return ans;
}
void init() {
for(int i = ; i < N; i++) {
for(int j = ; j < ; j++) {
for(int now = i; now; now /= ) {
f[i][j] += fastPow(now % , j);
}
}
}
} int main() {
init();
int T; scanf("%d", &T);
for(int cas = ; cas <= T; cas++) {
scanf("%d%d", &x, &k);
LL ans = ;
for(int i = ; i < base; i++)
v[i] = f[i][k] - i * base;
sort(v, v + base); for(int i = ; i < base; i++) {
LL ret = f[i][k] - i;
ans += upper_bound(v, v + base, x - ret) - lower_bound(v, v + base, x - ret);
} ans -= (x == );
printf("Case #%d: ", cas);
printf("%lld\n", ans);
}
return ;
}
/*
*/

hdu 5936 2016ccpc 杭州 - D的更多相关文章

  1. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  2. HDU 5936 Difference ( 2016 CCPC 杭州 D && 折半枚举 )

    题目链接 题意 : 给出一个 x 和 k 问有多少个 y 使得 x = f(y, k) - y .f(y, k) 为 y 中每个位的数的 k 次方之和.x ≥ 0 分析 : f(y, k) - y = ...

  3. HDU 5936 Difference(折半搜索(中途相遇法))

    http://acm.hdu.edu.cn/showproblem.php?pid=5936 题意: 定义了这样一种算法,现在给出x和k的值,问有多少个y是符合条件的. 思路: y最多只有10位,再多 ...

  4. hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1

    F - Rotational Painting Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  5. hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  6. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  8. HDU 5936 Difference

    题意: 有一个函数f(y, k) = y的每个十进制位上的数字的k次幂之和 给x, k 求 有多少个y满足 x = f(y, k) - y 思路: (据说这叫中途相遇法?) 由于 x >= 0 ...

  9. hdu 4741 2013杭州赛区网络赛 dfs ***

    起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...

随机推荐

  1. bzoj千题计划141:bzoj3532: [Sdoi2014]Lis

    http://www.lydsy.com/JudgeOnline/problem.php?id=3532 如果没有字典序的限制,那么DP拆点最小割即可 加上字典序的限制: 按c从小到大枚举最小割边集中 ...

  2. Nginx模块Lua-Nginx-Module学习笔记(二)Lua指令详解(Directives)

    源码地址:https://github.com/Tinywan/Lua-Nginx-Redis Nginx与Lua编写脚本的基本构建块是指令. 指令用于指定何时运行用户Lua代码以及如何使用结果. 下 ...

  3. Table of Contents

    程序设计 Java JavaSE Apache Commons Servlet & JSP Maven JMS ActiveMQ WebService CXF Jersey HttpClien ...

  4. ASP.NET项目与IE10、IE11不兼容的解决办法

    1.解决办法 机器级别修复, 服务器所有ASP.NET程序受益 需要去微软下载对应asp.NET版本的修补程序 .NET 4 -http://support.microsoft.com/kb/2600 ...

  5. MI-NOTE黑砖

    机型:MI NOTE LTE  miui7刷机老是报错,remote:partition table doesn't exist,分区表不存在,于是使用磁盘模式,也看到警告不要中途拔下来,但是不知道是 ...

  6. C# 中printDocument打印、预览、打印机设置和打印属性的方法

    private void Form1_Load(object sender, System.EventArgs e) { //获取或设置一个值,该值指示是否发送到文件或端口 printDocument ...

  7. 训练赛第二场G题 ZOJ 2343

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2343 解题报告:首先我假设最后的正确的结果是a[1] , a[2 ...

  8. AutoCAD DevTV-AUTOCAD二次开发资源合集

    Webcast Language Date AutoCAD .Net - Session 2 English 13-Sep-12 AutoCAD .Net - Session 1 English 6- ...

  9. 二叉树前中后/层次遍历的递归与非递归形式(c++)

    /* 二叉树前中后/层次遍历的递归与非递归形式 */ //*************** void preOrder1(BinaryTreeNode* pRoot) { if(pRoot==NULL) ...

  10. re-sign重签名

    准备: ① re-sign.jar重签名工具:(下载地址为:http://troido.de/downloads/category/1): ② 从D:\Android\sdk\build-tools\ ...