hdu 5936 2016ccpc 杭州 - D
数学题好难啊!!!!
最长长度不超过十位, 折半枚举。。。
#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的更多相关文章
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 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 = ...
- HDU 5936 Difference(折半搜索(中途相遇法))
http://acm.hdu.edu.cn/showproblem.php?pid=5936 题意: 定义了这样一种算法,现在给出x和k的值,问有多少个y是符合条件的. 思路: y最多只有10位,再多 ...
- hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1
F - Rotational Painting Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 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 ...
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 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 ...
- HDU 5936 Difference
题意: 有一个函数f(y, k) = y的每个十进制位上的数字的k次幂之和 给x, k 求 有多少个y满足 x = f(y, k) - y 思路: (据说这叫中途相遇法?) 由于 x >= 0 ...
- hdu 4741 2013杭州赛区网络赛 dfs ***
起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...
随机推荐
- css选择器 nth-child
html代码: <div> <p>多云转晴</p> <p>多云转晴</p> <p>多云转晴</p> <p> ...
- 2. Jmeter压力测试简单教程(包括服务器状态监控) (转)
转自:https://blog.csdn.net/cbzcbzcbzcbz/article/details/78023327 前段时间公司需要对服务器进行压力测试,包括登录前的页面和登录后的页面,主要 ...
- SQL语句(十九)——存储过程(练习)
select * From Student select * From Course select * from SC --INSERT INTO SC (Sno, Cno, Grade) --VAL ...
- [整理]document.execCommand()
http://msdn.microsoft.com/en-us/library/ms533049%28VS.85%29.aspx http://blog.csdn.net/lhrhi/article/ ...
- R爬虫实战1(学习)—基于RVEST包
这里用Hadley Wickham开发的rvest包.再次给这位矜矜业业开发各种好用的R包的大神奉上膝盖. 查阅资料如下: rvest的github rvest自身的帮助文档 rvest + CSS ...
- java后台代码发送邮件
1:安装 eyoumailserversetup 易邮邮件服务器 注册账号 2:安装Foxmail 登录以后会有个还原页面 3:测试 4:java 代码编写 配置文件: mail.host=http ...
- vue开发者工具vue-devtools-4.1.4_0.crx谷歌插件下载及安装
网盘地址: https://pan.baidu.com/s/14PoaihUHQZEJtiHNWUmdjg 下载好后 谷歌浏览器中扩展程序,开启开发者模式,将下载的文件拖到窗口中即可 然后重启浏览器 ...
- bootstrap-datetimepicker中设置中文
1.引入插件文件,同时引入相应的语言文件 <script src="bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.j ...
- Servlet笔记1--概述
JavaEE概述及系统架构分析: (1) JavaEE概述: (2) 系统架构分析:
- ActiveMQ与SpringMVC整合实现发送PTP和订阅发布消息功能
实现一个基于SpringMVC+JMS+ActiveMQ+Tomcat+JDK1.8+IDEA工具 ,Spring4.1.0和ActiveMQ5.15整合的实例,实现PTP和订阅/发布两种消息模型 一 ...