POJ-2282-The Counting Problem
2013-06-24 18:55
369 查看
本来是个搜索题,但是发现用数学的方法做的,队友讲的
代码:
代码:
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int n,m,ansa[11],ansb[11]; void GetNum(int num,int *ans) { for(int i=1;i<=9;i++) { int x=num,index=10,now=10; int sum=x/10; if(i<=x%10) sum++; while(x) { if(index*10>x) { if(i==x/index%10) sum+=x%index+1; else if(i<x/index%10) sum+=now; break; } if(i<x/index%10) sum+=(x/index/10+1)*now; else sum+=(x/index/10)*now; if(i==x/index%10) sum+=x%index+1; now*=10; index*=10; } ans[i]=sum; } int i=1,k=0,r; int x=num; while(x>=10) { r=x%10; x/=10; if(r) ans[0]+=i*x; else ans[0]+=(x-1)*i+k+1; k+=r*i; i*=10; } } int main() { while(scanf("%d%d",&n,&m)&&(n+m)) { memset(ansa,0,sizeof(ansa)); memset(ansb,0,sizeof(ansb)); if(n>m) swap(n,m); n--; GetNum(m,ansb); GetNum(n,ansa); printf("%d",ansb[0]-ansa[0]); for(int i=1;i<10;i++) printf(" %d",ansb[i]-ansa[i]); printf("\n"); } return 0; }
相关文章推荐
- POJ 2282 The Counting Problem
- poj 2282 The Counting Problem && poj 3286 How many 0's? (数位dp)
- POJ - 2282 - The Counting Problem - (计数问题)
- POJ 2282 The Counting Problem
- POJ2282:The Counting Problem(数位DP)
- poj 2282 The Counting Problem & 3286 How many 0's?
- [POJ] 2282 -> The Counting Problem
- POJ 2282 && HDU 1663 The Counting Problem(数论)
- POJ 3286 How many 0's? / 2282 The Counting Problem 排列组合统计数字
- POJ 2282 The Counting Problem & POJ 3286 How many 0's?(按位计算贡献)
- POJ 2282-The Counting Problem(组合数学_区间计数)
- POJ 2282 The Counting Problem
- POJ 2282 The Counting Problem,组合数学
- POJ题目2282 The Counting Problem(数学)
- poj 2282 The Counting Problem (数位DP)
- Poj 2282 The Counting Problem[统计区间 0 - 9出现的次数]
- (Realx 数论1.28)POJ 2282 The Counting Problem(区间统计数字:统计a、b之间各个数字(0~9)出现的次数)
- 统计区间[a,b]各个数字出现的个数:poj 2282 The Counting Problem poj 3286
- POJ 2282 The Counting Problem (数位dp)
- poj 2282 The Counting Problem 按位统计