NBUT [1475] Bachelor
[1475] Bachelor
- 时间限制: 1000 ms 内存限制: 65535 K
- 问题描述
- 炎热的暑期集训就要结束了,在这短短的20天,大家都很努力,因为很多都是光棍嘛。balabala
所以 Marknoon 先森一直耿耿于怀,毕竟他也是单身嘛。
有一天,Marknoon 先森看着一串数字,发现了那个跟他同命相连的数字1,所以他就开始无聊起来,想知道从数字1到数字N,一共出现了几个1。
例如N=12,则1的个数为5,出现1的数字分别为1,10,11,12。 - 输入
- 输入一个数N(1 <= N <= 2147483647)。
- 输出
- 输出从1到N中所有数字里出现 1 的个数。
- 样例输入
3
13
123- 样例输出
1
6
57- 提示
无
- 来源
Hungar
按位置计算,即分别计算个位,十位,百位,千位 。。。的 出现的次数,然后将他们的个数和输出
这里以 为例进行说明: 个位为 的情况 : _ _ _ 横线部分 可以是 到 的任意数字 所以个位 一共有 215个 ------- ( + )
十位为 的情况: _ _ _ 横线部分 可以是 到 的任意数字 十位 一共有 个 ------- ( +)*
百位为 的情况: _ _ _ 横线部分 可以是 到 的任意数字 百位 一共有 个 ------ * + +
千位为 的情况: _ _ _ 横线部分 可以是 到 的任意数字 千位 一共有 个 ------ ( + )*
当然 还有 为 的情况 如果是 的话 则 有 * ---- 十位 有 个
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; char str[];
int digit[]; long long Zero[]={,,,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12}; int cal(int l,int r){ //得到digit数组里面[i,j]区间构成的数
int ans=;
for(int i=l;i<=r;i++)
ans=ans*+digit[i];
return ans;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%s",str)){
int len=strlen(str);
for(int i=;i<len;i++)
digit[i]=str[i]-'';
long long ans=;
int l,r;
for(int i=;i<len;i++){
l=cal(,i-);
if(digit[i]>) //如果数字大于1 则用左边 digit[0,i-1] 构成的数 加1 乘上 10的(右边位数)次方
ans+=(l+)*Zero[len--i];
else if(digit[i]==){ //如果数字等于1 则用左边 digit[0,i-1] 构成的数 乘上 10的(右边位数)次方 后 加上 右边digit[i,len-1] 构成的数 再加上1
r=cal(i+,len-);
ans+=l*Zero[len--i]+r+;
}else if(digit[i]==) //如果数字等于0 则用左边digit[0,i-1] 构成的数 直接乘上 10的(右边位数)次方
ans+=l*Zero[len--i];
}
cout<<ans<<endl;
}
return ;
}
NBUT [1475] Bachelor的更多相关文章
- noj [1475] Bachelor (找1的个数)
http://ac.nbutoj.com/Problem/view.xhtml?id=1475 [1475] Bachelor 时间限制: 1000 ms 内存限制: 65535 K 问题描述 炎热的 ...
- NBUT 1457 莫队算法 离散化
Sona Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Submit Status Practice NBUT 145 ...
- - >code vs 1475 m进制转十进制
1475 m进制转十进制 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 将m进制数n转化成一个 ...
- ACM: NBUT 1107 盒子游戏 - 简单博弈
NBUT 1107 盒子游戏 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1105 多连块拼图 - 水题 - 模拟
NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ...
- ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector
NBUT 1646 Internet of Lights and Switches Time Limit:5000MS Memory Limit:65535KB 64bit IO Fo ...
- NBUT 1525 Cow Xor(01字典树+前缀思想)
[1525] Cow Xor 时间限制: 2000 ms 内存限制: 65535 K 问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个 ...
- NBUT 1186 Get the Width(DFS求树的宽度,水题)
[1186] Get the Width 时间限制: 1000 ms 内存限制: 65535 K 问题描述 It's an easy problem. I will give you a binary ...
- NBUT 1635 Explosion(最小顶点覆盖)
[1635] Explosion 时间限制: 10000 ms 内存限制: 65535 K 问题描述 there is a country which contains n cities connec ...
随机推荐
- PHPExcel合并与拆分单元格
$objPHPExcel; $filepath="c:\temp.xlsx"; try { $objReader = PHPExcel_IOFactory::createRea ...
- c/c++ sizeof运算符详解以及对象大小
原文:http://krystism.is-programmer.com/posts/41468.html 学过c的都知道sizeof运算符.不过还是需要注意以下几点.先从c的sizeof说起: 1. ...
- oauth2-server-php-docs 存储 学说2
学说2 创建客户端和访问令牌存储 要把学说融入到你的项目中,首先要建立你的实体.我们先从客户端,用户和访问令牌模型开始: yaml YourNamespace\Entity\OAuthClient: ...
- 编译安装openssl报错:POD document had syntax errors at /usr/bin/pod2man line 69. make: *** [install_docs]
错误如下: cms.pod around line 457: Expected text after =item, not a number cms.pod around line 461: Expe ...
- 是否缺少对 Microsoft.CSharp.dll 和 System.Core.dll 的引用?
错误提示 : 预定义的类型“Microsoft.CSharp.RuntimeBinder.Binder”未定义或未导入 是否缺少对 Microsoft.CSharp.dll 和 System.Core ...
- JavaWeb之tomcat安装、配置与使用(一)
一.Tomcat下载与安装: 1.直接到官网下载Tomcat安装程序包:http://tomcat.apache.org/ 2.下载下来后是个压缩包,如:apache-tomcat-7.0.40.zi ...
- 如何导入外部Git仓库到中国源代码托管平台(Git@OSC)
git clone --bare http://git.rcrtm.com/git/dianli.git git clone --mirror https://git.oschina.net/cand ...
- gson 忽略掉某些字段不进行转换
增加 transient 修饰进行解决,例如: private transient final DecimalFormat df = new DecimalFormat("#0.00&qu ...
- Max SPA
Stingray Response_ContentType Stingray javascript 其实是支持返回原生html的, 有了这个事情就简单了 RHTML - Response_Conten ...
- HDFS之FileStatus
任何文件系统的一个重要特性都是提供其目录结构浏览和检索它所存文件和目录相关信息的功能.FileStatus对象封装了文件系统中文件和目录的元数据,包括文件的长度.块大小.备份数.修改时间.所有者以及权 ...