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.

Input

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.

Output

On a single line print a single integer — the answer to the problem.

Examples

input

2 47

output

12

input

47 1024

output

98

Note

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;
}

  

时间: 2025-01-16 11:09:44

Codeforces Round #129 (Div. 2) C的相关文章

Codeforces Round #129 (Div. 1)E. Little Elephant and Strings

Codeforces Round #129 (Div. 1)E. Little Elephant and Strings 题意:给出n个字符串,问每个字符串有多少个子串(不同位置,相同的子串视作不同)至少出现在这n个字符串中的k个当中. 解法:这题学到了一个SAM的新技能,对于这多个串,建SAM的时候,不是把它们连在一起,建立SAM,而是先给它们建立Trie树,然后广搜这棵Trie树,对于Trie树上的V节点,在建SAM的时候,它应该接在Trie树上他的父亲节点后面,我们用TtoM[U]表示Tr

Codeforces Round #129 (Div. 2) B

Description The Little Elephant loves sortings. He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of

Codeforces Round #129 (Div. 2) A

Description The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend m

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #424 (Div. 2) E. Cards Sorting(线段树)

题目链接:Codeforces Round #424 (Div. 2) E. Cards Sorting 题意: 将n个数放进一个队列,每次检查队首,看看是不是队列中最小的数,如果是就扔掉,如果不是就放到队尾. 这样直到队列为空,为需要操作多少次. 题解: 考虑用两个指针模拟,最开始now指针指向第一个数,然后nxt指针指向下一个将要被删除的数. 然后我们要算出这里需要移动多少步,然后删掉这个数,一直重复操作,直到将全部的数删完. nxt指针可以用set来维护,now指针可以用并查集来维护. 计

Codeforces Round #366 (Div. 2) ABC

Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 1 #I hate that I love that I hate it 2 n = int(raw_input()) 3 s = "" 4 a = ["I hate that ","I love that ", "I hate it","I love it"] 5 fo

二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

题目传送门 1 /* 2 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 using namespace std; 8 9 const int MAXN = 5e2 + 10; 10 const int MAXM = 1e6 + 10; 11 const int INF = 0

CodeCraft-19 and Codeforces Round #537 (Div. 2) - D. Destroy the Colony(动态规划+组合数学)

Problem  CodeCraft-19 and Codeforces Round #537 (Div. 2) - D. Destroy the Colony Time Limit: 2000 mSec Problem Description Input Output For each question output the number of arrangements possible modulo 10^9+7. Sample Input abba21 41 2 Sample Output