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 ...
随机推荐
- MAT(Memory Analyzer tool)使用
当线上环境出现OOM/内存泄漏了,怎么办? 让虚拟机在发生内存溢出时 Dump 出当前的内存堆转储快照,配置-XX:+HeapDumpOnOutOfMemoryError, 当出现OOM时,分析dum ...
- c# 下实现ping 命令操作
1>通过.net提供的类实现 using System; using System.Collections.Generic; using System.Linq; using System.Te ...
- Mips下交叉编译dropbear
1. 编译zlib-1.2.8 在编译dropbear的时候,会遇到“configure: error: *** zlib missing - install first or check confi ...
- UOJ#22. 【UR #1】外星人
传送门 分析 我们发现一个很神的性质,就是对于一个数如果放在它之前的数小于它那它一定对答案没有贡献 于是我们用dp[i][j]表示从大往小考虑了前i个数,当前答案是j的方案数 我们知道它由两种情况转移 ...
- laravel查询最后执行的一条sql语句
- 新的云主机 python 创建虚拟环境
1.为什么要搭建虚拟环境? 问题:如果在一台电脑上, 想开发多个不同的项目, 需要用到同一个包的不同版本, 如果使用上面的命令, 在同一个目录下安装或者更新, 新版本会覆盖以前的版本, 其它的项目就无 ...
- windows phone 8 新增功能:从一个应用程序启动另一个程序(file association 和 Protocol association两种方式)
一. 启动手机预装内置程序打开文件file association 这里以打开word文档为例子 string fileToLaunch = @"HelloKitty.docx"; ...
- C++初始化,之不明白篇 cout<<x<<endl 与 cout<<"x = "<<cout<<x<<endl的输出的值会不一样
代码如下 #include <iostream> using namespace std; class point { public : int x; int y; ...
- C# 常用正则验证[转]
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- C# 由范式编程==运算符引发对string内存分配的思考
今天在看C#编程指南时(类型参数的约束http://msdn.microsoft.com/zh-cn/library/d5x73970.aspx)看到一段描述: 在应用 where T : class ...