poj 3286 How many 0's? 按位统计
2015-04-09 00:41
295 查看
题意:
给m<=n,求从m写到n,一共写多少个0.
分析:
按位算当某位是0时左边有多少种情况,右边有多少种情况,注意左边的情况数为-1时(这时遍历到最高位)是为了把右边多加的情况减去,也就是把0作为开头时的情况减去。
代码:
给m<=n,求从m写到n,一共写多少个0.
分析:
按位算当某位是0时左边有多少种情况,右边有多少种情况,注意左边的情况数为-1时(这时遍历到最高位)是为了把右边多加的情况减去,也就是把0作为开头时的情况减去。
代码:
//poj 3286 //sep9 #include<iostream> using namespace std; typedef __int64 ll; ll b[16]; ll f(ll n) { ll left,m,ans=0; for(int i=1;i<13;++i){ left=n/b[i]-1; ans+=left*b[i-1]; m=(n%b[i]-n%b[i-1])/b[i-1]; if(m>0) ans+=b[i-1]; else if(m==0) ans+=n%b[i-1]+1; if(b[i]>n) break; } return ans; } int main() { ll m,n; b[0]=1; for(int i=1;i<=12;++i) b[i]=b[i-1]*10; while(scanf("%I64d%I64d",&m,&n)&&n!=-1){ printf("%I64d\n",f(n)-f(m-1)); } return 0; }
相关文章推荐
- POJ 3286 How many 0's? / 2282 The Counting Problem 排列组合统计数字
- POJ 3286 How many 0's? (数位dp)
- poj 3286 How many 0's?
- poj 3286 How many 0's? --- 数位dp
- POJ 3286 How many 0's?(数论)
- POJ 3286 How many 0's?(数位dp)
- POJ 3286- How many 0's?(组合数学_区间计数)
- POJ 3286 How many 0's?
- POJ 3286 How many 0's?(数位DP)
- POJ 3286 How many 0's?
- Poj 3286 How many 0's? + Bzoj 1833 count 数字计数(数位统计)
- How many 0's? - POJ 3286 数位dp
- poj 3286 How many 0's?
- poj-3286-How many 0's?
- POJ - 3286 - How many 0's? - (统计0的个数)
- POJ 2282 The Counting Problem & POJ 3286 How many 0's?(按位计算贡献)
- POJ 3286 How many 0's?
- poj 2282 The Counting Problem && poj 3286 How many 0's? (数位dp)
- poj 3286 How many 0's?
- Poj 3286 How many 0's?