http://codeforces.com/problemset/problem/204/A

题意:给定一个【L,R】区间,求这个区间里面首位和末尾相同的数字有多少个

思路:考虑这个问题满足区间加减,我们只考虑【1,n】,考虑位数小于n的位数的时候,我们枚举头尾的数是多少,然后乘上10的某幂次,再考虑位数相等时,从高位往低位走,先考虑头尾数字小于最高位的情况,也像刚才那个随便取,当头尾数字等于最高位时,从高往低走,先算不与这位相等的,走下一步就代表与这位相等。最后要记得判断一下如果原数字头等于尾,答案要加1.

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<algorithm>
  6. #define ll long long
  7. ll st[];
  8. ll solve(ll x){
  9. if (x<=){
  10. return std::min(9LL,x);
  11. }
  12. if (x<=){
  13. ll t=x/10LL;
  14. return 9LL+t-+(t<=(x%));
  15. }
  16. ll res=;
  17. int top=;
  18. while (x){
  19. st[++top]=x%;
  20. x/=;
  21. }
  22. ll s=;
  23. for (int i=;i+<=top;i++){
  24. res+=*s;
  25. s*=10LL;
  26. }
  27. for (int i=;i<st[top];i++){
  28. res+=s;
  29. }
  30. s/=;
  31. for (int i=top-;i>=;i--)
  32. {
  33. for (int j=;j<st[i];j++)
  34. res+=s;
  35. s/=;
  36. }
  37. if (st[]>=st[top]) res++;
  38. return res;
  39. }
  40. int main(){
  41. ll n,m;
  42. scanf("%I64d%I64d",&n,&m);
  43. printf("%I64d\n",solve(m)-solve(n-));
  44. }

Codeforces 204A Little Elephant and Interval的更多相关文章

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

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

  2. CodeForces - 204C Little Elephant and Furik and Rubik

    CodeForces - 204C Little Elephant and Furik and Rubik 个人感觉是很好的一道题 这道题乍一看我们无从下手,那我们就先想想怎么打暴力 暴力还不简单?枚 ...

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

    题意: 有一种个位数与最高位数字相等的数字,求在l,r的范围内,这样的数字的个数. 思路: 找下规律就知道当当n>10的时候除去个位以后的答案等于n/10,然后考虑第一个数字是否小于最后一个.小 ...

  4. CodeForces 259A Little Elephant and Chess

     Little Elephant and Chess Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d &am ...

  5. CodeForces 221D Little Elephant and Array

    Little Elephant and Array Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on C ...

  6. A. Little Elephant and Interval

    The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r ( ...

  7. Codeforces 220B - Little Elephant and Array 离线树状数组

    This problem can be solve in simpler O(NsqrtN) solution, but I will describe O(NlogN) one. We will s ...

  8. Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp

    Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...

  9. Codeforces 258C Little Elephant and LCM

    Little Elephant and LCM #include<bits/stdc++.h> #define LL long long #define fi first #define ...

随机推荐

  1. java并发5-volatile关键字解析

    http://www.cnblogs.com/dolphin0520/p/3920373.html 一.内存模型的相关概念 大家都知道,计算机在执行程序时,每条指令都是在CPU中执行的,而执行指令过程 ...

  2. js原型继承深入

    js采用原型继承来实现类的派生,但是原型链再深入点,我们又知道多少呢,现在不妨往下看: 先来一个原型继承: var M1 = function() { this.param = "m1's ...

  3. 使用java创建kafka的生产者和消费者

    创建一个Kafka的主题,连接到zk集群,副本因子3,分区3,主题名是test111        [root@h5 kafka]# bin/kafka-topics.sh --create --zo ...

  4. hadoop2.2.0的WordCount程序

    package com.my.hadoop.mapreduce.wordcount; import java.io.IOException; import org.apache.hadoop.conf ...

  5. paip.输入法编程---增加码表类型

    paip.输入法编程---增加码表类型 作者Attilax ,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attil ...

  6. 简单干净的C# MVC设计案例:BrothersDropdownList()

    团队切换器 在/Teams/Details?id=xxx的页面,有这样一个控件,使得不需要回到/Teams/Index就能轻松切换团队: 由于这种团队切换控件比比皆是,比如在团队故事板中(以及其他地方 ...

  7. ORACLE表空间

    在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成. 如下图所示,一个数据库由对应 ...

  8. android .9.png ”点九” 图片制作方法

    “点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png 智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向, ...

  9. wxWidgets刚開始学习的人导引(3)——wxWidgets应用程序初体验

    wxWidgets刚開始学习的人导引全文件夹   PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wx ...

  10. Hadoop-2.2.0中文文档—— Common - CLI MiniCluster

    目的 使用 CLI MiniCluster, 用户能够简单地仅仅用一个命令就启动或关闭一个单一节点的Hadoop集群,不须要设置不论什么环境变量或管理配置文件. CLI MiniCluster 同一时 ...