题意:

有一种个位数与最高位数字相等的数字,求在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. 通过sql查询rman备份信息

    通过sql查询rman备份信息 查看所有备份集 SELECT A.RECID "BACKUP SET", A.SET_STAMP, DECODE (B.INCREMENTAL_LE ...

  2. line-height与vertical-align

    css世界读书笔记: 内联元素与流 块级元素负责结构,内联元素接管内容 x元素的下边缘就是我们的基线baseline x-height就是x的高度 vertical-align:middle是x中点位 ...

  3. JAVA使用JDBC连接MySQL数据库 一

    public class JDBCTest { public static void main(String[] args){ String driver = "com.mysql.jdbc ...

  4. SPOJ COT2 - Count on a tree II(LCA+离散化+树上莫队)

    COT2 - Count on a tree II #tree You are given a tree with N nodes. The tree nodes are numbered from  ...

  5. iOS-app发布证书和调试证书配置

    iOS-app发布证书.真机调试证书.测试证书.推送证书详细过程 更重要的是让你彻底明白为什么要这样配置证书 说句废话:凡事当你弄清楚为什么时,就揭开了它复杂和神秘的面纱 正文开始 一:发布证书 遵旨 ...

  6. python 对比两个字典的差异

    实际遇到的问题逻辑很繁杂,就不全写了.最后是通过对比两个字典差异来解决的.找出两个字典的差异,可参考以下代码. dict1 = {'a':1,'b':2,'c':3,'d':4} dict2 = {' ...

  7. 几个实用的 jQuery 插件

    1. owl.carousel -- 强大实用的jQuery幻灯片插件 2. jquery.nicescroll.min.js -- 自定义滚动条样式,支持 div,iframe,html 等. 3. ...

  8. js scrollTop, 滚动条操作

    设置页面加载时滚动条自动滚到底的方法: jQuery: 复制代码 代码如下: $(function(){ var h = $(document).height()-$(window).height() ...

  9. Linux文件的权限与属性

    由于以前学习Linux的时候没有做比较全面的总结笔记,而且平时大部分工作都在windows上进行,所以关于Linux的一些知识点有所遗忘.近期难得空闲,翻阅书籍,学习<鸟哥的Linux私房菜&g ...

  10. hdu 1573(中国剩余定理)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...