有坑!!!当x==0时,因为y>0,a,b不能同时为0,所以答案要-1

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<string.h>
#include<math.h>
#include<list> using namespace std; #define ll long long
#define pii pair<int,int>
const int inf = 1e9 + ; const int N = 1e5+; inline int read(){
int x;
char ch;
while(!isdigit(ch=getchar()));
x=ch-'';
while(isdigit(ch=getchar())){
x=x*+ch-'';
}
return x;
} ll f[N][];
ll val[N]; ll qPow(int a,int n){
ll ans=;
ll tmp=a;
while(n){
if(n&){
ans*=tmp;
}
tmp*=tmp;
n>>=;
}
return ans;
} ll F(int y,int k){
ll ans=;
while(y){
ans+=qPow(y%,k);
y/=;
}
return ans;
} void Init(){
for(int i=;i<N;++i){
for(int j=;j<;++j){
f[i][j]=F(i,j);
}
}
} ll slove(ll x,int k){
const ll os=1e5;
for(int y=;y<os;++y){
val[y]=f[y][k]-(ll)y*os;
}
sort(val,val+os);
ll ans=;
for(int y=;y<os;++y){
ll tmp=f[y][k]-y;
ans+=upper_bound(val,val+os,x-tmp)-lower_bound(val,val+os,x-tmp);
}
return ans-(x==);
} int main()
{
//freopen("/home/lu/Documents/r.txt","r",stdin);
//freopen("/home/lu/Documents/w.txt","w",stdout);
int k,T;
ll x;
scanf("%d",&T);
Init();
for(int t=;t<=T;++t){
scanf("%lld%d",&x,&k);
ll ans=slove(x,k);
printf("Case #%d: %lld\n",t,ans);
}
return ;
}

二分

#include <bits/stdc++.h>
#define pi acos(-1);
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = + ;
const int mod = 1e9 + ; map<LL, LL> mp[]; LL F(LL y, LL k)
{
LL tmp, ans=, mul=;
while(y){
tmp = y%;
mul = ;
for(LL i=; i<=k; i++) mul *= tmp;
ans += mul;
y/=;
}
return ans;
} void init()
{
for(LL k=; k<=; k++){
for(LL i=; i<; i++){
mp[k][F(i, k)-i*]++;
//if(F(i, k)-i*100000 == 0) printf("----%lld %lld\n", i, k);
}
}
} int main()
{
init();
LL T, k, x, cas=; scanf("%lld", &T);
while(T--){
scanf("%lld%lld", &x, &k);
LL ans = ;
for(LL i=; i<=; i++){
if(mp[k].count(x-F(i, k)+i)){
ans += mp[k][x-F(i, k)+i];
//printf("...%lld\n", i);
}
//if(mp[k][x-F(i,k)+i]) printf("...%d %d %lld %lld\n", i, k, x-F(i, k)+i, mp[k][x-F(i,k)+i]);
}
printf("Case #%lld: %lld\n", ++cas, ans);
}
} /*
9
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9 */

STL

2016 ccpc 杭州 D.Difference hdu5936(折半枚举)的更多相关文章

  1. 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 = ...

  2. 2016 CCPC 杭州站 小结

    5题倒数第一,铜……(我就知道我们很稳!!!哼!! 这一次心态完全爆炸 开场我就没有按照平时的顺序读题 然后zr的A题wa 我F题T xl说B是一个最小生成树,又说是最小树形图,不会写 K题完全没思路 ...

  3. 2016 ccpc 杭州赛区的总结

    毕竟是在杭电比的,和之前大连的icpc不同,杭电毕竟是隔壁学校,来回吃住全都是在自家寝室,方便! 不过说到方便也是有点不方便,室友都喜欢玩游戏,即使我昨晚9.30就睡觉了,仍然是凌晨一点才睡着,233 ...

  4. 2016 CCPC 东北地区重现赛

    1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08   HDU5929 Basic Data Structure    模拟,双端队列 1.题意:模拟一个栈的操 ...

  5. Load Balancing 折半枚举大法好啊

    Load Balancing 给出每个学生的学分.   将学生按学分分成四组,使得sigma (sumi-n/4)最小.         算法:   折半枚举 #include <iostrea ...

  6. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  7. NYOJ 1091 超大01背包(折半枚举)

    这道题乍一看是普通的01背包,最最基础的,但是仔细一看数据,发现普通的根本没法做,仔细观察数组发现n比较小,利用这个特点将它划分为前半部分和后半部分这样就好了,当时在网上找题解,找不到,后来在挑战程序 ...

  8. ccpc杭州站 赛后总结

    Ccpc杭州站赛后总结 2017年11月4号五号,我参加了ccpc杭州站的比赛,我的队友是聂少飞和王艳,在4号一点半,举行了比赛开幕式,听着教练代表的发言,听着参赛选手代表的发言,听着志愿者的发言,都 ...

  9. Codeforces 888E - Maximum Subsequence(折半枚举(meet-in-the-middle))

    888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define l ...

随机推荐

  1. 面试题:String StringBufere StringBuilder 不用看

    一.String 使用 private final char value[]来实现字符串存储 所以String对象创建之后就不能再修改此对象中存储的字符串内容,所以说String本质是字符数组char ...

  2. wordpress+lnmp出现 404 Not Found nginx

    在本地使用Apache,因此进行重写规则是.htaccess文件,但在Nginx服务器中此文件不起作用. 只需在网站的虚拟机配置文件中添加如下 location / { if (-f $request ...

  3. Orace开源的异步IO编程库,特点是接口非常简单

    官网:https://oss.oracle.com/projects/libaio-oracle/,正如标题所说,非常简单了,不用多解释,请直接看头文件,其中aio_poll类似于poll,重要的结构 ...

  4. C# / .Net Core 访问MongoDb库

    话不多说直接上代码 连接字符串: { "AppSettings": { "mongodb": "mongodb://用户名:密码@IP地址:端口号&q ...

  5. php 可变数量的参数列表

    可变数量的参数列表 PHP 在用户自定义函数中支持可变数量的参数列表.在 PHP 5.6 及以上的版本中,由 ... 语法实现:在 PHP 5.5 及更早版本中,使用函数func_num_args() ...

  6. (c++11)随机数------c++程序设计原理与实践(进阶篇)

    随机数既是一个实用工具,也是一个数学问题,它高度复杂,这与它在现实世界中的重要性是相匹配的.在此我们只讨论随机数哦最基本的内容,这些内容可用于简单的测试和仿真.在<random>中,标准库 ...

  7. 《C#多线程编程实战》2.7 CountDownEvent

    这个同步线程的类大概是东北的. 很有意思. 会限定你的线程使用的次数,更形象一点的像是你妈,提前准备好你要使用的线程的次数,用不完还不高兴那种的. 使用顺序基本就是 实例化  填充线程的启动次数 使用 ...

  8. 互斥锁与join

    三 互斥锁与join 使用join可以将并发变成串行,互斥锁的原理也是将并发变成穿行,那我们直接使用join就可以了啊,为何还要互斥锁,说到这里我赶紧试了一下 #把文件db.txt的内容重置为:{&q ...

  9. golang文件处理函数openfile与linux系统的文件函数的耦合

    golang运行最理想的环境是linux系统中,编译速度和执行速度都比较快,本文是关于golang中的文件操作函数 在golang标准库中os包提供了不依赖平台的借口,但是使用的风格是unix风格的. ...

  10. kali linux之xss

    攻击web客户端 客户端脚本语言(弹窗,广告,在浏览器中执行,javascript) javascript--与java语言无关,使用最广的客户端脚本语言 xss(cross-site scripti ...