UVA 11361Investigating Div-Sum Property
来源:互联网 发布:linux初学者入门书籍 编辑:程序博客网 时间:2024/06/05 14:13
题意:求在[a,b]这个区间内有多少个数x满足,x%k==0&&x的各个位上的数的和y%k==0。
分析:《算法竞赛入门经典训练指南》数学基础例题5。
代码:
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<cstdio>#include<vector>#include<string>#include<cstring>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;const int N=2000010;const int MAX=151;const int MOD1=1000007;const int MOD2=100000009;const double EPS=0.00000001;typedef long long ll;const ll MOD=1000000007;const ll INF=10000000010;typedef unsigned long long ull;int k,q[12][90][90],dp[12][90][90],ten[12];int get(int w,int u,int v) { if (w==0&&u==0&&v==0) return 1; if (w==0) return 0; if (q[w][u][v]) return dp[w][u][v]; for (int i=0;i<10;i++) dp[w][u][v]+=get(w-1,((u+i)%k+k)%k,((v+i*ten[w])%k+k)%k); q[w][u][v]=1; return dp[w][u][v];}int d[15];int pd(int x) { int y=x,sum=0; while (x) { sum+=x%10;x/=10; } if (sum%k==0&&y%k==0) return 1; return 0;}int cala(int x) { int i,j,u=0,v=0,g=0,ret=0; if (pd(x)) ret++; while (x) { d[++g]=x%10;x/=10; } for (i=g;i>0;i--) { for (j=0;j<d[i];j++) ret+=get(i-1,((u+j)%k+k)%k,((v+j*ten[i])%k+k)%k); u=((u+d[i])%k+k)%k; v=((v+d[i]*ten[i])%k+k)%k; } return ret;}int main(){ int a,b,t,i; scanf("%d", &t); while (t--) { scanf("%d%d%d", &a, &b, &k); if (k>=90) printf("0\n"); else { memset(q,0,sizeof(q)); memset(dp,0,sizeof(dp)); ten[1]=1;for (i=2;i<=10;i++) ten[i]=(ten[i-1]*10%k+k)%k; printf("%d\n", cala(b)-cala(a-1)); } } return 0;}
0 0
- uva 11361 Investigating Div-Sum Property
- Investigating Div-Sum Property Uva 11361
- UVA - 11361 Investigating Div-Sum Property
- uva 11361 Investigating Div-Sum Property
- UVa 11361 Investigating Div-Sum Property
- uva 11361 Investigating Div-Sum Property
- UVA 11361Investigating Div-Sum Property
- UVa 11361Investigating Div-Sum Property
- UVa 11361 Investigating Div-Sum Property
- Investigating Div-Sum Property UVA
- 11361 - Investigating Div-Sum Property
- UVa 11361 Investigating Div-Sum Property / 数位DP
- UVA 11361 - Investigating Div-Sum Property(数位DP)
- uva 11361 - Investigating Div-Sum Property(数位dp)
- UVa 11361 - Investigating Div-Sum Property (数位DP)
- UVA 11361 Investigating Div-Sum Property(数位DP)
- UVa 11361 Investigating Div-Sum Property 数字和与倍数
- uva 11361 Investigating Div-Sum Property 数位dp
- UVALive 3516Exploring Pyramids
- Swift 中使用 SQLite——修改和删除数据
- 根据连续分布产生随机数一般方法
- ios面试试题总结(未整理)
- 第三届中国移动开发者大会(MDCON.2015)
- UVA 11361Investigating Div-Sum Property
- ios面试题2(未整理)
- JavaIO流
- 在CXF中自定义JSR 311 (Restful)的ExceptionMapper
- 近期总结-2015.11.17
- Windows环境下安装NodesJS
- JS积累
- 优化你的TipeView
- volatile浅析