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”三种中任意一种就输 ...
随机推荐
- 2017-2018-1 20179215《Linux内核原理与分析》第二周作业
20179215<Linux内核原理与分析>第二周作业 这一周主要了解了计算机是如何工作的,包括现在存储程序计算机的工作模型.X86汇编指令包括几种内存地址的寻址方式和push.pop.c ...
- vmware station中 UDEV 无法获取共享存储磁盘的UUID,症状: scsi_id -g -u -d /dev/sdb 无返回结果。
1.确认在所有RAC节点上已经安装了必要的UDEV包 [root@11gnode1 ~]# rpm -qa|grep udevsystem-config-printer-udev-1.1.16-25. ...
- Azure上部署FTP服务
FTP是个比较复杂的协议,其协议分为控制层和数据层,工作模式分为主动和被动两种模式. 在默认的Active模式下其工作原理如下: 可以看到,客户端发起FTP的请求道服务器端,FTP的端口是21.用户在 ...
- 文件异步上传,多文件上传插件uploadify
本文中使用java作为例子 uploadify下载 http://files.cnblogs.com/chyg/uploadify.zip jsp页面中需要引入: <script type=&q ...
- jquery easyui 推荐博客 (MVC+EF+EasyUI+Bootstrap)
构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(52)-美化EasyUI皮肤和图标 系列目录 我很久以前就想更新系统的皮肤功能,Easyui 自 ...
- ViewController lifecyle(IOS学习)
斯坦福的ios教学视频笔记一张,如下
- .clearfix:after
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- shell解决DOS攻击生产案例
解决DOS攻击生产案例企业实战题5:请用至少两种方法实现!写一个脚本解决DOS攻击生产案例.提示:根据web日志或者或者网络连接数,监控当某个IP并发连接数或者短时内PV达到100,即调用防火墙命令封 ...
- win7下在eclipse3.7中使用hadoop1.2.1插件运行MadReduce例子
环境 win7+hadoop_1.2.1+eclipse 3.7+maven 3 1.在win7下下载hadoop_1.2.1 2.安装hadoop的eclipse插件,注意eclipse 4.x版本 ...
- shell script-条件语句、循环语句
条件语句 #!/bin/bash read -p "input your name:" name #第一种判断 if [ "$name" == "Mi ...