codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
Posted brucemengbm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(贪心)的主要内容,如果未能解决你的问题,请参考以下文章
CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
Codeforces Round #722 (Div. 1)
Codeforces Round #462 (Div. 1) A A Twisty Movement
Codeforces Round #483 (Div. 1) A. Finite or not?
codeforces 559a//Gerald's Hexagon// Codeforces Round #313(Div. 1)