codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
题意:
有一种个位数与最高位数字相等的数字,求在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(贪心)的更多相关文章
- 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 ...
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- codeforces #578(Div.2)
codeforces #578(Div.2) A. Hotelier Amugae has a hotel consisting of 1010 rooms. The rooms are number ...
- codeforces #577(Div.2)
codeforces #577(Div.2) A Important Exam A class of students wrote a multiple-choice test. There are ...
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
随机推荐
- grep_awk_sed文本处理
小技巧 1.删除0字节文件find -type f -size 0 -exec rm -rf {} \; 2.查看进程按内存从大到小排列ps -e -o “%C : %p : %z : %a”|sor ...
- WINDOWS开发PHP7扩展
最近在做个项目,需要用到唯一ID的生成,原本在Java和Delphi中,做了一个生成20位字符串(160bit)形式的唯一ID的算法,但是对比GUID(128bit),除了看起来比他短之外,其他并无优 ...
- java同步器__学习笔记
参照:http://ifeve.com/introduce-abstractqueuedsynchronizer/ 前言: 在java.util.concurrent.locks包中有很多Lock的实 ...
- WebGIS的开发方式
(转)摘抄自<基于WebGIS的校友资源管理系统的设计与实现>_陈刚
- BZOJ 4827 [Shoi2017]分手是祝愿 ——期望DP
显然,考虑当前状态最少需要几步,直接贪心即可. 显然我们只需要考虑消掉这几个就好了. 然后发现,关系式找出来很简单,是$f(i) f(i+1) f(i-1)$之间的. 但是计算的时候并不好算. 所以把 ...
- Bajtman i Okrągły Robin
Bajtman i Okrągły Robin 题目描述 你是一个保安,你发现有n个强盗,其中第i个强盗会在[a[i],a[i]+1],[a[i]+1,a[i]+2],...,[b[i]-1,b[i] ...
- iOS - 倒计时封装
+(NSString *)countdownStartTime:(NSString *)startTime{ NSString *TIME = [startTime substringToIndex: ...
- Eclipse与MyEclipse增加主题
下载所需文件 下载地址:https://pan.baidu.com/s/1slq9lFn 如果eclipse和myeclipse里的MyEclipse 10\dropins存在features和plu ...
- WML标签速查手册 wap标签
原文发布时间为:2010-08-19 -- 来源于本人的百度文章 [由搬家工具导入] WML标签速查手册(转)比较方便便于速查 结构相关标签 语法及属性 <wml> <wml x ...
- SQL触发器的使用及语法
原文发布时间为:2010-08-07 -- 来源于本人的百度文章 [由搬家工具导入] ===以下转qsfwy.javaeye.com/blog/424789定义: 何为触发器?在SQL Server里 ...