B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)
1 second
256 megabytes
standard input
standard output
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should
be assigned with a number from 1 to n.
Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
The first line contains integer n (1 ≤ n ≤ 109)
— the number of books in the library.
Print the number of digits needed to number all the books.
13
17
4
4
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
题意:为1-n之中有多少个数字。比如10有两个数字。100有三个数字。
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; __int64 sum;
__int64 a[] = {0,9,90,900,9000,90000,900000,9000000,90000000,900000000};
__int64 b[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000};
__int64 n; int main(){
while(scanf("%I64d",&n)!=EOF){
sum = 0;
for(int i=1;i<=10;i++){
if(n>=b[i]){
sum += a[i]*i;
}else{
sum += (n - b[i-1] + 1)*i;
break;
}
}
if(n<10)
{
sum--;
}
printf("%I64d\n",sum);
}
}
B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)的更多相关文章
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)
B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 数学 Codeforces Round #308 (Div. 2) B. Vanya and Books
题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...
- 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales
题目传送门 /* 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
随机推荐
- JavaScript中字符串分割函数split用法实例
这篇文章主要介绍了JavaScript中字符串分割函数split用法,实例分析了javascript中split函数操作字符串的技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了JavaSc ...
- python毫秒级sleep
Python中的sleep函数可以传小数进去,然后就可以进行毫秒级的延时了 # 例1:循环输出休眠1秒 import time i = 1 while i = 3: print i # 输出i i + ...
- 《深入理解Android2》读书笔记(三)
接上篇<深入理解Android2>读书笔记(二) PackageManagerService PackageManagerService负责系统中Package的管理,应用程序的安装.卸载 ...
- Java并发编程实战笔记
如果当多个线程访问同一个可变的状态变量时没有使用合适的同步,那么程序就会出现错误.有三种方式可以修复这个问题: i.不在线程之间共享该状态变量 ii.将状态变量修改为不可变的变量 iii.在访问状态变 ...
- Structs2 校验框架
代码结构: 使用Struts校验框架,保证输入学生的基本信息:学号.姓名.性别.出生年月.专业.总学分等,要求输入满足以下条件:(1) 学号前两位大于“13”并且后面4位必须为数字:(2) 出生年月必 ...
- STL容器 -- Priority_Queue
核心:和队列相似,但优先队列中的 “下一个元素” 指的是 “优先级最高” 的元素. 头文件:#include<queue> 普通类型的构造方法: priority_queue<int ...
- Spring源码分析之Bean的加载流程
spring版本为4.3.6.RELEASE 不管是xml方式配置bean还是基于注解的形式,最终都会调用AbstractApplicationContext的refresh方法: @Override ...
- 【BZOJ 3309】DZY Loves Math
http://www.lydsy.com/JudgeOnline/problem.php?id=3309 \[\sum_{T=1}^{min(a,b)}\sum_{d|T}f(d)\mu(\frac ...
- 2017 Multi-University Training 2 解题报告
Is Derek lying? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 【BFS】The Morning after Halloween
[POJ3523]The Morning after Halloween Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 23 ...