2016 ccpc 杭州 D.Difference hdu5936(折半枚举)

有坑!!!当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(折半枚举)的更多相关文章
- 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 = ...
- 2016 CCPC 杭州站 小结
5题倒数第一,铜……(我就知道我们很稳!!!哼!! 这一次心态完全爆炸 开场我就没有按照平时的顺序读题 然后zr的A题wa 我F题T xl说B是一个最小生成树,又说是最小树形图,不会写 K题完全没思路 ...
- 2016 ccpc 杭州赛区的总结
毕竟是在杭电比的,和之前大连的icpc不同,杭电毕竟是隔壁学校,来回吃住全都是在自家寝室,方便! 不过说到方便也是有点不方便,室友都喜欢玩游戏,即使我昨晚9.30就睡觉了,仍然是凌晨一点才睡着,233 ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- Load Balancing 折半枚举大法好啊
Load Balancing 给出每个学生的学分. 将学生按学分分成四组,使得sigma (sumi-n/4)最小. 算法: 折半枚举 #include <iostrea ...
- CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。
1514: Packs Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 61 Solved: 4[Submit][Status][Web Board] ...
- NYOJ 1091 超大01背包(折半枚举)
这道题乍一看是普通的01背包,最最基础的,但是仔细一看数据,发现普通的根本没法做,仔细观察数组发现n比较小,利用这个特点将它划分为前半部分和后半部分这样就好了,当时在网上找题解,找不到,后来在挑战程序 ...
- ccpc杭州站 赛后总结
Ccpc杭州站赛后总结 2017年11月4号五号,我参加了ccpc杭州站的比赛,我的队友是聂少飞和王艳,在4号一点半,举行了比赛开幕式,听着教练代表的发言,听着参赛选手代表的发言,听着志愿者的发言,都 ...
- Codeforces 888E - Maximum Subsequence(折半枚举(meet-in-the-middle))
888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define l ...
随机推荐
- Angular26 ng-content和ng-container、投影的使用
1 准备工作 1.1 搭建angular环境 技巧01:本博文基于angular5 1.3 创建一个angular项目 技巧01:根据业务划分模块,每个模块都设定一个主组件 技巧02:利用路由实现模块 ...
- 显著水平alpha
http://blog.minitab.com/blog/adventures-in-statistics-2/understanding-hypothesis-tests:-significance ...
- Swing自定义JScrollPane的滚动条设置,重写BasicScrollBarUI方法
Swing自定义JScrollPane的滚动条设置,重写BasicScrollBarUI方法 摘自:https://blog.csdn.net/qq_31635851/article/details/ ...
- hdu 1556 Color the ball (线段树做法)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a ...
- delphi监控文件夹
(****************************************** 文件和目录监控 当磁盘上有文件或目录操作时,产生事件 使用方法: 开始监控: PathWatch(Self.Ha ...
- Javascript脚本 :Function 对象的定义和使用
javascript Function 对象的定义 创建函数的语法:var myFunction=new Function(arg1,arg2,...agrN,body);agrN 为函数的参数,b ...
- C++的惨痛教训(未完待续)
题记:只有痛才能让人铭记!痛促进进步~ 1. strncpy,大家都知道要做安全检查,可是谁都有嫌麻烦的时候,尤其是自己很自信不会产生溢出的时候,可能不会坑了自己,却会坑了使用这段代码的人.所以,1. ...
- 将以太坊封装为 ERC20
将以太坊封装为 ERC20 TOKEN 很多 DAPP 都是在处理 ERC20接口的 token, 其实很容易将以太坊封装为 ERC20,这样就可以统一处理, 至少我目前在做的雷电网络就是这么处理的. ...
- 十、Node.js-url模块
下面使用之前提到过的note交互模式(可以在cmd直接执行js代码)进行学习url模块 跳出note模式同样是Ctrl+C(两次) 学习url模块主要是要掌握url模块的方法: url.parse() ...
- 内联函数背景、例子、与普通函数的区别及要注意的地方 ------新标准c++程序设计
背景: 使用函数能够避免将相同代码重些多次的烦恼,还能减少可执行程序的体积,但也会带来程序运行时间上的开销.函数调用在执行时,首先在栈中为形参和局部变量分配存储空间,然后还要将实参的值复制给形参,接下 ...