PAT 1049 Counting Ones [难]
1049 Counting Ones (30 分)
The task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's in 1, 10, 11, and 12.
Input Specification:
Each input file contains one test case which gives the positive N (≤230).
Output Specification:
For each test case, print the number of 1's in one line.
Sample Input:
12
Sample Output:
5
题目大意:给出一个数m,计算1~m中的数包含的所有的1的个数。
//我绝对是看过这道题,但是真的想不起来怎么做了,当时就没怎么看懂。数据量这么大,指定不能一个一个算,需要技巧。
//个位是1+十位是1+。。。。。这样会不会有重复?不会吧。
//这个真的好难,看了好久才明白。
如何计算left和now和right也值得注意!自己求的话就不太会求的。
PAT 1049 Counting Ones [难]的更多相关文章
- PAT 1049 Counting Ones[dp][难]
1049 Counting Ones (30)(30 分) The task is simple: given any positive integer N, you are supposed to ...
- pat 1049. Counting Ones (30)
看别人的题解懂了一些些 参考<编程之美>P132 页<1 的数目> #include<iostream> #include<stdio.h> us ...
- pat 1049 Counting Ones
要统计1到N之间‘1’的个数,如数11包含2个1.所以当N=12时,答案为5. 思想: 找规律,假设ans[N]表示1到N的‘1’的个数,则有a[100]=(a[10]-1)*9+10+a[10]-1 ...
- PAT 甲级 1049 Counting Ones (30 分)(找规律,较难,想到了一点但没有深入考虑嫌麻烦)***
1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to co ...
- PAT甲级1049. Counting Ones
PAT甲级1049. Counting Ones 题意: 任务很简单:给定任何正整数N,你应该计算从1到N的整数的十进制形式的1的总数.例如,给定N为12,在1,10, 11和12. 思路: < ...
- PAT 解题报告 1049. Counting Ones (30)
1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...
- pat 甲级 1049. Counting Ones (30)
1049. Counting Ones (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The tas ...
- PAT (Advanced Level) 1049. Counting Ones (30)
数位DP.dp[i][j]表示i位,最高位为j的情况下总共有多少1. #include<iostream> #include<cstring> #include<cmat ...
- PAT甲级1049 Counting Ones【规律】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805430595731456 题意: 给定n,问0~n中,1的总个数 ...
随机推荐
- SQL Server从读写频繁的大表中删除大批量数据
如果我们直接用delete from语句来删除读写频繁的大表中的数据,很有可能会因为where的条件是全表扫描从而导致整个表被锁住了.如果该表是读写频繁的生产库那简直就是一场灾难,所有的线上读写请求都 ...
- 数据库 Proc编程二
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...
- Boosting with Abstention
论文提出了一种loss: x是原始数据,y是对应的label,h(x)是一个判别函数,r(x)相当于训练了一个信心函数,r(x)越大,代表对自己做的判断的信息越大,当r(x)<0的时候,就拒绝进 ...
- 22SpringMvc_jsp页面上的数据传递到控制器的说明
假设有这个一个业务:在jsp页面上写入数据,然后把这个数据传递到后台. 效果如下:
- 第二百六十节,Tornado框架-内置模板方法
Tornado框架-内置模板方法 直接在html文件使用,不需要传值 Tornado默认提供的这些功能其实本质上就是 UIMethod 和 UIModule,也就是Tornado框架定义好的html文 ...
- SSH三大框架的知识题
Struts 谈谈你对Struts的理解. 答: 1.struts是一个按MVC模式设计的Web层框架,其实它就是一个大大的servlet,这个Servlet名为ActionServlet,或是Act ...
- recyclerView中的方法
onCreateViewHolder(); onBindViewHolder(); getItemCount(); recyclerVIew中没有添加头布局和尾布局方法.可以用getItemViewT ...
- 华为 进入和退出Fastboot、eRecovery和Recovery升级模式
手机关机状态下,可以进入Fastboot/eRecovery / Recovery/升级这几种模式: 需要连接电脑:Fastboot模式:长按音量下键+电源键.eRecovery 模式:长按音量上键+ ...
- 【黑金原创教程】【TimeQuest】【第六章】物理时钟与外部模型
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...
- 【黑金原创教程】 FPGA那些事儿《概念篇》
简介一本讲述非软硬片上系统的书,另外还是低级建模的使用手册. 目录[黑金原创教程] FPGA那些事儿<概念篇>:File01 - 结构的玩笑[黑金原创教程] FPGA那些事儿<概念篇 ...