HDU 5936 Difference 折半枚举,暴力
来源:互联网 发布:运营商的云计算项目 编辑:程序博客网 时间:2024/06/07 07:11
/* 观察函数显然到1e10左右为负 先处理一半 再根据x 匹配另一半。*/#include<bits/stdc++.h>using namespace std;#define rep(i,a,b) for(int i=(a);i<=(b);++ i)typedef long long ll;const int N = 1e5+1;multiset<int> s[8];multiset<ll> s9;ll num[10][N];int Pow[10][10];ll f(ll x,int k){ ll ans=0; while(x) ans +=Pow[x%10][k],x /=10; return ans;}const int limit =1e5;int main(){ rep(i,1,9) rep(j,1,9) Pow[i][j] = j==1?i:Pow[i][j-1]*i; for(int k=1;k<=9;k++) { for(ll i=0;i<limit;i++) { num[k][i] =f(i,k)-(ll)i*limit; if(k<=8) s[k-1].insert((f(i,k))-i); else s9.insert((f(i,k))-i); } } int t,cas=0; cin>>t; while(t--) { int x,k; cin>>x>>k; int ans=0; for(int i=0;i<limit;i++) { int c; ll xx =x- num[k][i]; if((xx>1e9||xx<-1e9)&&k<=8) continue; if(k<=8) c =s[k-1].count(xx); else c =s9.count(xx); ans +=c; } if(x==0) ans--; cout<<"Case #"<<++cas<<": "<<ans<<endl; } return 0;}
阅读全文
0 0
- HDU 5936 Difference 折半枚举,暴力
- Hdu 5936 Difference【思维+折半枚举+二分】
- HDU 5936 Difference(折半枚举)
- HDU 5936 && 2016CCPC杭州 D: Difference(折半枚举)
- Smallest Difference (poj 2718 暴力枚举)
- poj 2718 Smallest Difference (STL 暴力枚举)
- POJ:2718 Smallest Difference(暴力枚举)
- POJ 2718 Smallest Difference(暴力枚举)
- hdu 3332 暴力枚举
- HDU 3823 暴力枚举
- hdu 3720 暴力枚举
- hdu 5024 暴力枚举
- hdu 4445 暴力枚举
- HDU 4007 暴力枚举
- hdu 5128 暴力枚举
- hdu 5228 暴力枚举
- hdu 5339 暴力枚举
- HDU 5610 暴力枚举
- 左右逆和伪逆
- python中scrapy的学习
- mysql-语句
- 时间复杂性求解
- 奇异值分解(SVD)原理详解及推导
- HDU 5936 Difference 折半枚举,暴力
- 关于mvp
- 世界名画陈列馆问题-重复&不重复两种
- 【2-SAT】【AtCoder Regular Contest 069 F】Flag
- Android中Json数据格式的解析
- Controller for AR.Drone
- An error occurred while collecting items to be installed session context was
- SEO网络优化是什么工作
- tensorflow的一些基本函数