Codeforces 204A Little Elephant and Interval
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的更多相关文章
- Codeforces D. Little Elephant and Interval(思维找规律数位dp)
题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...
- CodeForces - 204C Little Elephant and Furik and Rubik
CodeForces - 204C Little Elephant and Furik and Rubik 个人感觉是很好的一道题 这道题乍一看我们无从下手,那我们就先想想怎么打暴力 暴力还不简单?枚 ...
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
题意: 有一种个位数与最高位数字相等的数字,求在l,r的范围内,这样的数字的个数. 思路: 找下规律就知道当当n>10的时候除去个位以后的答案等于n/10,然后考虑第一个数字是否小于最后一个.小 ...
- CodeForces 259A Little Elephant and Chess
Little Elephant and Chess Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d &am ...
- CodeForces 221D Little Elephant and Array
Little Elephant and Array Time Limit: 4000ms Memory Limit: 262144KB This problem will be judged on C ...
- 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 ( ...
- 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 ...
- Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp
Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...
- Codeforces 258C Little Elephant and LCM
Little Elephant and LCM #include<bits/stdc++.h> #define LL long long #define fi first #define ...
随机推荐
- vsftpd,tftp安装配置
一. 对比共同点:都包含ftp不同点:1)vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.你可以通过ftp客户端上传下载软件.可设置访问用户名密码,或匿名anonymous登陆.默认 ...
- MPlayer播放器安装
http://www.mplayerhq.hu/MPlayer/releases/MPlayer-1.1.1.tar.xz [tim@L MPlayer-1.1.1]$ mplayer ...
- 【转】Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)
原文网址:http://embed.21ic.com/software/android/201403/31603.html 1 :Android中Spinner下拉列表(使用ArrayAdapter和 ...
- codeforces284 div1 B:概率dp
蛋疼的期末..好久没有A题了,,惭愧啊 昨晚打起精神准备做cf 结果竟然忘记注册了..拿学长号看了看题,今早起来补了一道dp 题目大意: 有n首歌,你需要边听边猜 对于第 i 首歌 每听一分钟你猜出它 ...
- New Year Permutation(Floyd+并查集)
Description User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to mak ...
- 学习DNS路上之CloudXNS
使用CloudXNS已经有两年了,趁着他们现在做活动的机会也发表一下这两年来使用感受与CloudXNS的变化,也对我学习使用的一次总结. 简介 CloudXNS是北京快网开发的一套授权DNS系统, 用 ...
- 广州Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Python偏函数实例
目标: 1.编写一个gui,生成按钮 2.通过偏函数,生成按钮 3.通过装饰器,实现按钮输出信息功能 1.使用Tkinter,创建一个按钮 代码如下: handetiandeMacBook-Pro:~ ...
- StoryBoard 设置TabBar SelectImage 和tintColor
如图:StoryBoard 结构是 Tabbar + Navi + ViewController 需求:需要修改TabBar的Image 和SelectImage 设置Image 设置SelectIm ...
- Android 之 资源文件的介绍及使用
Android 之 资源文件的介绍及使用 1.资源的简单介绍: 在res文件夹中定义:字符串.颜色.数组.菜单.图片.视频等:在应用程序中使用这些资源. 2.使用资源的长处:降低代码量,同一时候为 ...