Codeforces Round #129 (Div. 2) C
Description
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
The single line contains a pair of integers l and r (1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64dspecifier.
On a single line print a single integer — the answer to the problem.
2 47
12
47 1024
98
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
题意:有这种数字,第一位和最后一位相同,问你两个数字范围内有多少符合要求的数字~
解法:当然是找规律啊,很容易看出规律是9*10^n,然后考虑两个端点的情况,他们是不是也是符合要求的(这里的代码写的不清楚QAQ,最有价值的只有cmd函数了)
#include<bits/stdc++.h>
using namespace std;
long long a[100005];
int pos;
int n;
int d;
long long cmd(string s)
{
long long sum1=0,sum2=0;
if(s.length()==1)
{
sum1=0;
}
else if(s.length()==2)
{
sum1=9;
}
else
{
sum1=10;
for(int i=1;i<s.length()-2;i++)
{
sum1*=10;
}
// cout<<sum1<<endl;
sum1=sum1-1;
// cout<<sum1<<endl;
sum1+=9; }
int ans1=s[0]-'0'-1;
long long sum3=0;
long long pos1=1;
if(s.length()>=3)
{
for(int i=1; i<=s.length()-2; i++)
{
sum3=sum3*10+(s[i]-'0');
}
// sum3=sum3+1;
for(int i=0; i<s.length()-2; i++)
{
pos1*=10;
}
if((s[0]-'0')<=(s[s.length()-1]-'0'))
{
sum1=sum1+ans1*pos1+sum3+1;
}
else
{
sum1=sum1+ans1*pos1+sum3;
} }
else
{
if(s[0]<=s[s.length()-1])
{
sum1=sum1+ans1*pos1+sum3+1;
}
else
{
sum1=sum1+ans1*pos1+sum3;
}
}
return sum1;
}
int main()
{
string s1,s2;
cin>>s1>>s2;
// cout<<cmd(s1)<<endl;
// cout<<cmd(s2)<<endl;
if(s1[0]==s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)+1<<endl;
}
else if(s1[0]==s1[s1.length()-1]&&s2[0]>s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)+1<<endl;
}
else if(s1[0]<=s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)<<endl;
}
else if(s1[0]<=s1[s1.length()-1]&&s2[0]>s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)<<endl;
}
else if(s1[0]>s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)<<endl;
}
else if(s1[0]>s1[s1.length()-1]&&s2[0]>s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)<<endl;
}
else if(s1[0]>s1[s1.length()-1]&&s2[0]<=s2[s2.length()-1])
{
cout<<cmd(s2)-cmd(s1)<<endl;
}
return 0;
}
Codeforces Round #129 (Div. 2) C的更多相关文章
- Codeforces Round #129 (Div. 2)
A. Little Elephant and Rozdil 求\(n\)个数中最小值的个数及下标. B. Little Elephant and Sorting \[\sum_{i=1}^{n-1}{ ...
- 字符串(后缀自动机):Codeforces Round #129 (Div. 1) E.Little Elephant and Strings
E. Little Elephant and Strings time limit per test 3 seconds memory limit per test 256 megabytes inp ...
- Codeforces Round #129 (Div. 1)E. Little Elephant and Strings
题意:有n个串,询问每个串有多少子串在n个串中出现了至少k次. 题解:sam,每个节点开一个set维护该节点的字符串有哪几个串,启发式合并set,然后在sam上走一遍该串,对于每个可行的串,所有的fa ...
- Codeforces Round #129 (Div. 2) B
Description The Little Elephant loves sortings. He has an array a consisting of n integers. Let's nu ...
- Codeforces Round #129 (Div. 2) A
Description The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. &quo ...
- Educational Codeforces Round 129 (Rated for Div. 2) A-D
Educational Codeforces Round 129 (Rated for Div. 2) A-D A 题目 https://codeforces.com/contest/1681/pro ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- 【JVM】jvm垃圾回收器相关垃圾回收算法
引用计数法[原理]--->引用计数器是经典的也是最古老的垃圾收集防范.--->实现原理:对于对象A,只要有任何一个对象引用A,则计数器加1.当引用失效时,计数器减1.只要对象A的计数器值为 ...
- Guice总结
Guice总结 Jar包:guice-4.1.0.jar 辅包: guava-15.0.jar aopalliance-.jar javaee-api-6.0-RC2.jar Guice的IoC 两种 ...
- 修改MySQL的时区,涉及参数time_zone (转)
首先需要查看mysql的当前时区,用time_zone参数 mysql> show variables like '%time_zone%'; +------------------+----- ...
- yum软件包管理器
Yum (Yellow dog Updater, Modified) 黄狗升级器是一个在 Fedora 中的字符前端软件包管理器.基于 RPM 包管理(介绍见RPM包及其管理),能够从指定的服务器自动 ...
- 人物-IT-张朝阳:张朝阳
ylbtech-人物-IT-张朝阳:张朝阳 张朝阳,1964年10月31日出生在陕西省西安市,搜狐公司董事局主席兼首席执行官.1986年毕业于清华大学物理系,并于同年考取李政道奖学金赴美留学.1993 ...
- JavaScript-Tool-富文本:UEditor
ylbtech-JavaScript-Tool-富文本:UEditor UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协 ...
- 使用变参函数实现pwd命令
#include "stdafx.h"#include <Windows.h> #define DIRNAME_LEN (MAX_PATH+2) BOOL PrintS ...
- docker出现错误 could not read CA certificate
1. 问题描述 $ docker login # 无法正常使用 其他一堆命令,显示验证失败之类的问题 2. 解决方案 $ unset DOCKER_TLS_VERIFY $ unset DOCKER_ ...
- C/C++的区别
C和C++的关系:就像是win98跟winXP的关系.C++是在C的基础上增加了新的理论,玩出了新的花样.所以叫C加加. C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设 ...
- 谁是Docker的开发者
由CHRIS DAWSON发表在thenewstack/DATA RESEARCH qianhen123/CHB译 我们分析了Docker的容器库并提出两个问题: 1.Docker的贡献者们感兴趣的其 ...