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

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

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

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define ll long long
ll st[];
ll solve(ll x){
if (x<=){
return std::min(9LL,x);
}
if (x<=){
ll t=x/10LL;
return 9LL+t-+(t<=(x%));
}
ll res=;
int top=;
while (x){
st[++top]=x%;
x/=;
}
ll s=;
for (int i=;i+<=top;i++){
res+=*s;
s*=10LL;
}
for (int i=;i<st[top];i++){
res+=s;
}
s/=;
for (int i=top-;i>=;i--)
{
for (int j=;j<st[i];j++)
res+=s;
s/=;
}
if (st[]>=st[top]) res++;
return res;
}
int main(){
ll n,m;
scanf("%I64d%I64d",&n,&m);
printf("%I64d\n",solve(m)-solve(n-));
}

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. 开发者应当了解的WebKit知识

    开发者应当了解的WebKit知识 对一些开发者而言,WebKit就是一个黑盒子.丢进去HTML.CSS.JS等一连串的东西,而WebKit就能变魔术一般显示出一个很棒的网页出来.实际上,正我的同事Il ...

  2. js中iframe的用法

    最近遇到的项目总是习惯左边一个树,点击每个树的节点右边出现相应的信息,遇到这种情况用iframe还是很简单的, 例如 : 页面文件 @section Tree{ <ul id="tre ...

  3. HDU_2040——判断亲和数

    Problem Description 古希腊数学家毕达哥拉斯在自然数研究中发现,220的所有真约数(即不是自身的约数)之和为: 1+2+4+5+10+11+20+22+44+55+110=284.  ...

  4. 将 Web 应用性能提高十倍的10条建议

    提高 web 应用的性能从来没有比现在更重要过.网络经济的比重一直在增长:全球经济超过 5% 的价值是在因特网上产生的(数据参见下面的资料).这个时刻在线的超连接世界意味着用户对其的期望值也处于历史上 ...

  5. 迭代导出word 文档

    Map迭代的使用: Map map = new HashMap() ; Iterator it = map.entrySet().iterator() ; while (it.hasNext()) { ...

  6. 小结OC中Retain cycle(循环引用)

    retain cycle 的产生 说到retain cycle,首先要提一下Objective-C的内存管理机制. 作为C语言的超集,Objective-C延续了C语言中手动管理内存的方式,但是区别于 ...

  7. (转)iOS5:[UIDevice uniqueIdentifier]的替代方案

    背景: 大多数应用都会用到苹果设备的UDID号,UDID通常有以下两种用途: 1)用于一些统计与分析目的:[第三方统计工具如友盟,广告商如ADMOB等] 2)将UDID作为用户ID来唯一识别用户,省去 ...

  8. 修改文件所有者 chown

    将upload目录权限改为777,sudo chmod 777 upload,再测试上传功能成功.但这种修改权限的方法并不安全.故可以改upload目录的拥有者为www-data(即apache)   ...

  9. Android编程之ActivityManager: Segmentation fault

    今天运行代码时,出现了一个不能运行的故障问题:ActivityManager: Segmentation fault 是的,这个原因网上有诸多解释:包名不能是中文或者非法字符,或者重启新的avd来解决 ...

  10. 漏洞都是怎么编号的CVE/CAN/BUGTRAQ/CNCVE/CNVD/CNNVD

    在一些文章和报道中常常提到安全漏洞CVE-1999-1046这样的CVE开头的漏洞编号,这篇文章将常见的漏洞ID的表示方法做下介绍: 1.以CVE开头,如CVE-1999-1046这样的 CVE 的英 ...