Codeforces Round #452 (Div. 2)
来源:互联网 发布:配乐朗诵录音软件 编辑:程序博客网 时间:2024/06/13 23:12
题意:
从1-n挑两个数,加起来后缀9最多。输出有几组。
POINT:
先根据n判断最多有几个9,明显是以5 50 500来分的界限。
然后从0999,1999,2999,,,,,8999来分别考虑。对每一个算出l和r。
#include <stdio.h>#include <math.h>#include <algorithm>using namespace std;#define LL long longconst LL maxn = 200000+444;LL a[13];LL b[13];void init(){a[1]=9;b[1]=10;for(LL i=2;i<=12;i++)a[i]=a[i-1]*10+9,b[i]=b[i-1]*10;}LL n;LL query(LL x,LL pos){LL cnt=x*b[pos]+a[pos];LL l=max(1LL,cnt-n);LL r=min(n,cnt-1);if(l<r) return (r-l+1)/2;return 0;}int main(){init();scanf("%lld",&n);if(n<=4){printf("%lld\n",n*(n-1)/2);}else{LL now=5;LL pos=0;while(n>=now){pos++;now*=10;}LL ans=0;for(LL i=0;i<9;i++){ans+=query(i,pos);}printf("%lld\n",ans);}return 0;}
阅读全文
0 0
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2)
- Codeforces Round #452 (Div. 2) A-C
- Codeforces Round #452 (Div. 2) C
- Codeforces Round #452 (Div. 2)划水报告
- Codeforces Round #452 (Div. 2) D
- Codeforces Round #452 (Div. 2) A
- Codeforces Round #452 (Div. 2) B
- Codeforces Round #452 (Div. 2) C
- Codeforces Round #452 (Div. 2) D
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Android系统下C语言hello world
- numpy/arrayobject.h”: No such file or directory
- serialVersionUID的作用
- CentOS 6 python2.7 virtualenv 环境搭建
- 在Ubuntu系统、GPU模式下运行Fast R-cnn代码
- Codeforces Round #452 (Div. 2)
- LC- Island Perimeter
- IT行业风险投资
- 学习笔记13
- MySQL基础教程14-Mysql插入中文数据报错的原因和解决办法
- 10019---SpringBoot简介
- IM即时聊天室(二): Socket.io + Node.js
- glance获取镜像图解
- JVM类与类加载器