CSU 1642 Problem B
来源:互联网 发布:阿里云服务器动态ip 编辑:程序博客网 时间:2024/05/17 09:22
转自:http://blog.csdn.net/lizhaowei213/article/details/48091947
其实就是打表。现在看来也挺水的一道题。
可为什么当时没做出来呢,因为那时候水平还达不到。
方法:先从1到最大值打表。上一个状态1出现的个数,加上当前数字1的个数。然后区间两个值一减即可。
代码:
- #include <stdio.h>
- #define N 1000005
- int dp[N];
- int getcnt(int x)
- {
- int cnt=0;
- while(x>0)
- {
- if(x%10==1)
- cnt++;
- x/=10;
- }
- return cnt;
- }
- void gettable()
- {
- for(int i=1;i<=1000000;i++)
- dp[i]=getcnt(i)+dp[i-1];
- }
- int main()
- {
- gettable();
- int a,b;
- while(scanf("%d%d",&a,&b)>0)
- printf("%d\n",b>a?dp[b]-dp[a-1]:dp[a]-dp[b-1]);
- return 0;
- }
阅读全文
0 0
- CSU 1642 Problem B
- CSU 1642 Problem B
- csu Problem B: String and Arrays
- CSU: B
- CSU-ACM暑假集训基础组训练赛(1) B - Problem B
- CSU-ACM暑假集训基础组训练赛(2) B - Problem B
- CSU-ACM暑假集训基础组训练赛(5-1) B - Problem B
- csu Problem C: Double
- csu A Easy Problem
- CSU Monthly 2012 Apr Problem B: 信使核糖核酸转录后剪接
- CSU - 1155 |a-b|
- csu Problem D: Long Long
- Problem B
- Problem B
- Problem B
- Problem B
- Problem B
- Problem B
- 增长黑客-之“bug营销”范例及设想思考!
- obs-studio 断线重连
- linux下PXE和KickStart实现Linux下的无人值守安装
- eclipse下新建jsp页面失败,提示错误。
- 小米5调试出现DELETE_FAILED_INTERNAL_ERROR错误
- CSU 1642 Problem B
- CodeForces 813A|813B|813C|813D
- Linux 下配置静态ip地址
- Java 类加载机制详解
- [Leetcode] 200. Number of Islands 解题报告
- 欢迎使用CSDN-markdown编辑器
- 解决margin-top塌陷的6种方法
- 单链表的练习
- Centos7.2安装CDH5.7.2core steps