题意:

有一种个位数与最高位数字相等的数字,求在l,r的范围内,这样的数字的个数。

思路:

找下规律就知道当当n>10的时候除去个位以后的答案等于n/10,然后考虑第一个数字是否小于最后一个。小于减一,还要加上个位一定存在的9位数


import java.util.Scanner; public class xxz { public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long l = sc.nextLong();
long r = sc.nextLong();
long ans = solve(r) - solve(l-1);
System.out.println(ans); } public static long solve(long x){
String _x = String.valueOf(x);
return x/10 -1 + Math.min(9,x)+(_x.charAt(0) <= _x.charAt(_x.length() - 1) ? 1 : 0); } }

codeforces 204(Div.1 A) Little Elephant and Interval(贪心)的更多相关文章

  1. Codeforces #617 (Div. 3) D. Fight with Monsters(贪心,排序)

    There are nn monsters standing in a row numbered from 11 to nn . The ii -th monster has hihi health ...

  2. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  3. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  4. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

  5. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  6. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  7. codeforces #578(Div.2)

    codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...

  8. codeforces #577(Div.2)

    codeforces #577(Div.2) A  Important Exam A class of students wrote a multiple-choice test. There are ...

  9. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. c语言有用函数收集

    1 strtok :分解字符串为一组字符串.s为要分解的字符串,delim为分隔符字符串.首次调用时,s指向要分解的字符串,之后再次调用要把s设成NULL. 2 strstr :从字符串str1中查找 ...

  2. [atcoder002E] Candy Piles [博弈论]

    题面: 传送门 思路: 每一堆糖排成一列,所有列横着放,形成一个阶梯型 两个决策相当于左边一列去掉和最下面一行去掉 那么这个模型可以转化为同样形状的网格图,向左上方走,走到边界的赢· 然后一波数学推导 ...

  3. BZOJ 4590 [Shoi2015]自动刷题机 ——二分答案

    二分答案水题. #include <cstdio> #include <cstring> #include <iostream> #include <algo ...

  4. 七牛云的cdn配置

    https://segmentfault.com/q/1010000004265556

  5. 模板jinja2常用方法

    http://docs.jinkan.org/docs/jinja2/ 摘自 http://www.pythontip.com/blog/post/5455/ 数学运算       +, -, *,  ...

  6. HTML 删除和添加字

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. python没学好

    环境 装东西用pip3不是pip 运算 //是下取整 py的浮点数也没有大小限制,但是超出一定范围就直接表示为inf 条件语句与循环 if xxx:, elif:, else:, 'for x in ...

  8. P1143 飘飘乎居士的约会

    P1143 飘飘乎居士的约会 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景  一阵狂风吹过  只听“pong”的一声,飘飘乎居士降落了!!! 描述 又是美妙 ...

  9. 收藏一下这个微软MVP的老外博客

    原文发布时间为:2011-04-20 -- 来源于本人的百度文章 [由搬家工具导入] http://blog.overridethis.com/blog  http://haacked.com htt ...

  10. JavaScript 之类型转换

    数值转换成字符串类型 1.利用 “+” 将数值加上一个长度为零的空字符串. 2.通过toString()方法.加入参数可以直接进行进制的转换. <script language="ja ...