HDU 5085/BC 15D Counting problem
来源:互联网 发布:手机网络挣钱 编辑:程序博客网 时间:2024/05/29 14:52
题意:设函数f(x,k)为x的每一位的k次方的和,求a到b中有多少i满足,f(i,k)=S (a,b,k,S给定)
题解:
自己想的比较复杂 首先k为1 2时可以特殊处理 因为此时的S也很小,正常的数位dp就可以了
而k>2时 可以先拆分S 这时S的拆分种数较少,对每一种再进行计算即可。
但这样不好敲啊=。= 忍不住看了题解,果然机智,分治即可,预处理储存S的后几位,再枚举S的前几位既可。
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include<list>#include<set>#include<map>#include<stack>#include<queue>#include<deque>#define mem(x,y) memset(x,y,sizeof(x))#define pb push_backusing namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int,double> pii;#define bug puts("===========");#define zjc puts("");const double pi=(acos(-1.0));const double eps=1e-8;const ll INF=1e18+10;const ll inf=1e9+10;const int mod=1e9+7;const int maxn=1000+10;const int maxm=1e5+5;ll p[15][20];ll fuck[maxm][17];map<ll,ll>mp;ll cnt(ll n,ll k){ ll x=0; while(n){ x += p[n%10][k]; n/=10; } return x;}ll go(ll n,ll k,ll s){ if(n<=1e6){ ll ans=0; for(ll i=1;i<=n;i++) if(cnt(i,k)==s) ans++; return ans; } mp.clear(); ll len=1e4; for(ll i=0;i<len;i++){ ll now=fuck[i][k]; mp[now]++; } ll nn=n/len,ans=mp[s]; for(ll i=1;i<nn;i++){ ll now=fuck[i][k]; if(now<=s&&mp.count(s-now)) ans+=mp[s-now]; } ll z=cnt(nn,k),nnn=n%len; for(ll j=0;j<=nnn;j++){ if(fuck[j][k]==s-z) ans++; } return ans;}int main(){ for(ll i=1;i<=9;i++){ p[i][0]=1; for(ll j=1;j<16;j++){ p[i][j]=p[i][j-1]*i; } } int len=1e5; for(int k=1;k<=15;k++) for(int i=1;i<=len;i++) fuck[i][k]=cnt(i,k); ll a,b,k,s; while(~scanf("%I64d%I64d%I64d%I64d",&a,&b,&k,&s)){ ll ans=go(b,k,s)-go(a-1,k,s); printf("%I64d\n",ans); }}
0 0
- HDU 5085/BC 15D Counting problem
- HDU 5085 Counting problem
- HDU 4910 / BC 3D Problem about GCD
- hdu 5085 Counting problem (分块+二进制优化下hash链表)
- HDU 4959 / BC 5D Poor Akagi
- HDU 4992 / BC 8D Primitive Roots
- HDU 5779/BC 85D Tower Defence
- HDU 5434/BC 54D Reflect
- HDU 5688 Problem D
- HDU - 5688 Problem D
- hdu 5688 Problem D
- HDU 5431/BC 54A A problem of sorting
- BC D Revenge of kNN II hdu 5021
- hdu 5613 /BC 69D Baby Ming and Binary image
- HDU 5603/BC 67D the soldier of love
- HDU 4984 / BC 6D Goffi and Graph
- 【STL】hdu 5688 Problem D
- HDU 5082/BC 15A Love
- linux携带密码登录其他远程机
- Apache 服务器下载、安装、应用
- Java 8: Lambda Expression
- shiro令牌环
- Lightoj1265 Island of Survival 概率题
- HDU 5085/BC 15D Counting problem
- javascript对文档对象模型DOM的基本操作学习笔记
- Javacard DES/AES/RSA/Hash/Sinature算法API使用示例
- 实习菜鸟的成长(一)
- SDWebImage的探索(1)
- VS2013快捷键
- TCP/IP,HTTP,socket,长连接和短连接
- iOS 9出现错误Applications are expected to have a root view controller at the end of application launch
- 市场营销学