码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 204(Div.1 A) Little Elephant and Interval(贪心)

时间:2017-07-29 10:16:55      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:tty   pen   范围   type   force   java   tracking   math   art   

题意:
有一种个位数与最高位数字相等的数字,求在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(贪心)

标签:tty   pen   范围   type   force   java   tracking   math   art   

原文地址:http://www.cnblogs.com/brucemengbm/p/7253467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!