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 ...
随机推荐
- /error处理
1 BasicErrorController 1.1 简述 SpringMVC框架在出现错误时有一个默认的错误请求 /error:出现异常之后执行/error请求之前框架会判断出现异常的请求类型,然后 ...
- c语言实践 创建两个包含8个元素的double类型数组,第二个元素的每个元素的值都是对应前一个元素的前n个元素的和
意思就是第二个元素的num[2]等于第一个元素的num[0]+num[1]+num[2] #define COUNT 8 int main(void) { double num1[COUNT]; do ...
- 264E Roadside Trees
传送门 题目大意 分析 倒着跑LIS表示以i为开头的LIS,于是对于删除可以暴力重算前10棵树.而对于种树,因为高度不超过10且高度两两不同,所以暴力重算比它矮的10棵树即可.对于需要重算的点,将其从 ...
- 使用rpmbuild打包时不对文件进行strip操作
使用rpmbuild打包时不对文件进行strip操作 摘自: https://www.ichenfu.com/2017/11/20/rpmbuild-not-strip/ By Chen Fu 发表于 ...
- What is the AppData folder?
Applies to Windows 8.1, Windows RT 8.1 The AppData folder contains app settings, files, and data spe ...
- Capturing ASP.NET Application Startup Exceptions
It has become common practice to perform tasks during an ASP.NET applications start up process. Thes ...
- Android内置和外置SD卡的位置获取
public class StorageUtils { private static String TAG="123"; // 获取主存储卡路径 内置内存卡路径 public st ...
- 【转】android中layout_weight的理解
android Layout_weight的理解 SDK中的解释: Indicates how much of the extra space in the LinearLayout will be ...
- 微软和Google的盈利模式对比分析
一: 微软和Google是世界上最成功科技巨头之一,但他们之间却有着不同的产品和业务,二者的盈利方式也各有不同,本文将分析和探讨的二者盈利模式的异同. 微软的盈利模式 在1975年由大学肄业的Bill ...
- web端访问文件没有权限的问题
背景 : ftp的PHP项目中的某些文件没有写入的权限..系统报注意错误!!! 原因 : 一般情况下,web端访问网站一般使用的是WWW权限(有限制的权限组)去访问, 但是我们编程开发的时候, 有可能 ...