UVALive3261 UVA1640 POJ2282 HDU1663 ZOJ2392 The Counting Problem
来源:互联网 发布:数据集成方案ppt 编辑:程序博客网 时间:2024/06/15 21:56
Regionals 2004 >> Asia - Shanghai
问题链接:UVALive3261 UVA1640 POJ2282 HDU1663 ZOJ2392 The Counting Problem。
问题简述:输入m和n,计算m到n(包括m和n)之间各个数中包含多少个0-9数字。
问题分析:先分别计算0到m-1和0到n之间数的数字个数,结果=0到n之间数的数字个数-0到m-1之间数的数字个数。计算0到n之间数的数字个数时,先考虑1位数、2位数、......,在小于n的区间逐步统计。程序说明:数组radix[]计算存放10进制的位权备用。函数countdigit()用于统计0到n之间数的0-9个数。
这个程序在POJ中,用C语言提交出现错误,也许是其C语言版本太低有关,用GCC提交可以通过。其他地方用C语言提交即可。
类似程序参见:POJ3286 How many 0's?。
AC的C语言程序如下:
/* UVALive3261 UVA1640 POJ2282 HDU1663 ZOJ2392 The Counting Problem */#include <stdio.h>typedef long long LL;#define MAXN 10LL radix[MAXN+1];void maketable(){ int i; radix[0] = 1; for(i=1; i<=MAXN; i++) radix[i] = radix[i-1] * 10;}LL countdigit(LL n, int digit){ LL sum=0, dgt, left, right; int i; for(i=1;;i++) { left = n / radix[i]; sum += (left -((digit==0)?1:0)) * radix[i-1]; dgt = n % radix[i] / radix[i-1]; if (dgt > digit) sum += radix[i-1]; else if(dgt == digit) { right = n % radix[i-1]; sum += right + 1; } if (n < radix[i]) break; } return sum;}int main(void){ maketable(); int a, b, i; while(scanf("%d%d", &a, &b) != EOF && a+b) { if(a > b) { int temp = a; a = b; b = temp; } for(i=0; i<=9; i++) printf("%lld%c", countdigit(b, i) - countdigit(a-1, i), (i==9)?'\n':' '); } return 0;}
1 0
- UVALive3261 UVA1640 POJ2282 HDU1663 ZOJ2392 The Counting Problem
- The Counting Problem poj2282
- poj2282 The Counting Problem
- POJ2282 The Counting Problem:
- UVa1640 - The Counting Problem(数位统计)
- POJ2282:The Counting Problem(数位DP)
- poj2282 The Counting Problem 数位dp
- POJ2282:The Counting Problem找规律
- pku2282 The Counting Problem
- WOJ1254-The Counting Problem
- The Counting Problem UVA
- pku 2282 The Counting Problem
- poj 2282 The Counting Problem
- POJ-2282-The Counting Problem
- [POJ] 2282 -> The Counting Problem
- POJ 2282 The Counting Problem
- UVa 1640 The Counting Problem
- POJ 2282 The Counting Problem
- Java面经-1
- 关于poi读取中的一些坑
- 解决父布局具有点击效果,但是子布局的Button不响应点击事件的问题
- java基础--14.如何正确地写出单例模式
- Dubbo学习记录二
- UVALive3261 UVA1640 POJ2282 HDU1663 ZOJ2392 The Counting Problem
- 最大乘积子数组
- Kubernetes 知多少?
- LeetCode | Jump Game II
- 数据结构实验之排序七:选课名单
- gitbub 上删除仓库
- 集合的伪随机遍历
- 内连接、左外连接、右外连接、交叉连接区别
- 剑指Offer_32_把数组排成最小的数