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”三种中任意一种就输 ...
随机推荐
- POJ-2564 01背包问题
#include"cstdio" #include"cstring" #include"algorithm" using namespace ...
- BZOJ4545: DQS的trie
BZOJ4545: DQS的trie https://lydsy.com/JudgeOnline/problem.php?id=4545 分析: 对trie用dfs建sam复杂度是\(O(n^2)\) ...
- 【Lintcode】364.Trapping Rain Water II
题目: Given n x m non-negative integers representing an elevation map 2d where the area of each cell i ...
- 使用svnadmin对VisualSVN进行项目迁移
使用svnadmin对VisualSVN进行项目迁移 导出1> 启动命令行cmd2> 运行%VISUALSVN_SERVER%\bin\svnadmin dump PATH-TO-REPO ...
- mybatis---demo1--(缓存)----bai
News-mapper.xml 配置: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ma ...
- SpringMvc之参数绑定注解详解之三
2. @RequestHeader.@CookieValue @RequestHeader 注解,可以把Request请求header部分的值绑定到方法的参数上. 示例代码: 这是一个Request ...
- 拖动调整div布局大小
一.需求 实现类似windows软件的那种,拖动调整两个div的大小 二.结果示例: 三.示例代码: https://github.com/CinYung/jQuery.divResizer.git
- js数组中的reverse()方法
reverse方法是将数组中的元素的顺序进行反转,在原数组上操作,然后返回原数组.由于本人是学习js的新人,对reverse函数进行了几个小实验,以下实验均在Chrome浏览器上运行 实验一:reve ...
- JavaScript高级程序设计学习笔记第十五章--使用Canvas绘图
一.基本用法 1.要使用<canvas>元素,必须先设置其 width 和 height 属性,指定可以绘图的区域大小.能通过 CSS 为该元素添加样式,如果不添加任何样式或者不绘制任何图 ...
- Select 标签的默认值设置
以下是网上“借鉴”的:(http://blog.csdn.net/nairuohe/article/details/6307367/) 比如<select class="selecto ...