NBUTOJ1475: Bachelor
来源:互联网 发布:淘宝网5.0旧版本下载 编辑:程序博客网 时间:2024/04/29 20:31
http://ac.nbutoj.com/Problem/view.xhtml?id=1475
炎热的暑期集训就要结束了,在这短短的20天,大家都很努力,因为很多都是光棍嘛。balabala
所以 Marknoon 先森一直耿耿于怀,毕竟他也是单身嘛。
有一天,Marknoon 先森看着一串数字,发现了那个跟他同命相连的数字1,所以他就开始无聊起来,想知道从数字1到数字N,一共出现了几个1。
例如N=12,则1的个数为5,出现1的数字分别为1,10,11,12。
所以 Marknoon 先森一直耿耿于怀,毕竟他也是单身嘛。
有一天,Marknoon 先森看着一串数字,发现了那个跟他同命相连的数字1,所以他就开始无聊起来,想知道从数字1到数字N,一共出现了几个1。
例如N=12,则1的个数为5,出现1的数字分别为1,10,11,12。
输入一个数N(1 <= N <= 2147483647)。
输出从1到N中所有数字里出现 1 的个数。
313123
1657
已经第三次看到这道题了,无力吐槽
原理:http://blog.csdn.net/qingniaofy/article/details/8764926
#include <stdio.h>#include <math.h>__int64 CountOne(__int64 n)//数1的个数{ __int64 count =0; if (n ==0) count =0; else if (n >1&& n <10) count =1; else { __int64 highest = n; __int64 bit =0; while (highest >=10) { highest = highest /10; bit++; } __int64 weight = (__int64)pow(10, bit); if (highest ==1) { count = CountOne(weight -1)+ CountOne(n - weight)+ n - weight +1; } else { count = highest * CountOne(weight -1)+ CountOne(n - highest * weight) + weight; } } return count;}int main(){ __int64 n; while(~scanf("%I64d",&n)) { printf("%I64d\n",CountOne(n)); } return 0;}
- NBUTOJ1475: Bachelor
- nbutoj1475
- Happy bachelor day!
- Happy Bachelor's Day!
- NBUT 1475 Bachelor
- Bachelor's song
- NOJ [1475] Bachelor
- UVa12114 - Bachelor Arithmetic(水题)
- Bachelor 1-n间有几个1
- air max pas cher femme wearing a Bachelor of service before graduation
- char, wchar_t,UTF8,UNICODE,GBK转换
- 读stl源码之后对list容器的一点感想
- python面试
- SQL RIGHT JOIN
- android ViewFlipper的使用
- NBUTOJ1475: Bachelor
- WPF图片模糊的解决之路
- Hercules 开启TCP/IP FTP 服务
- hadoop环境的安装与搭建
- poj 2285 状态压缩~最优方案
- JDBC连接oracle数据库
- StringBuilder与StringBuffer和String 的区别
- 在使用jquery的ajax功能时,往后台传值会出现乱码 解决方法
- 【DB2】 管理tablespace 与 container 、buffer pool