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 ...
随机推荐
- java并发5-volatile关键字解析
http://www.cnblogs.com/dolphin0520/p/3920373.html 一.内存模型的相关概念 大家都知道,计算机在执行程序时,每条指令都是在CPU中执行的,而执行指令过程 ...
- js原型继承深入
js采用原型继承来实现类的派生,但是原型链再深入点,我们又知道多少呢,现在不妨往下看: 先来一个原型继承: var M1 = function() { this.param = "m1's ...
- 使用java创建kafka的生产者和消费者
创建一个Kafka的主题,连接到zk集群,副本因子3,分区3,主题名是test111 [root@h5 kafka]# bin/kafka-topics.sh --create --zo ...
- hadoop2.2.0的WordCount程序
package com.my.hadoop.mapreduce.wordcount; import java.io.IOException; import org.apache.hadoop.conf ...
- paip.输入法编程---增加码表类型
paip.输入法编程---增加码表类型 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attil ...
- 简单干净的C# MVC设计案例:BrothersDropdownList()
团队切换器 在/Teams/Details?id=xxx的页面,有这样一个控件,使得不需要回到/Teams/Index就能轻松切换团队: 由于这种团队切换控件比比皆是,比如在团队故事板中(以及其他地方 ...
- ORACLE表空间
在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成. 如下图所示,一个数据库由对应 ...
- android .9.png ”点九” 图片制作方法
“点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png 智能手机中有自动横屏的功能,同一幅界面会在随着手机(或平板电脑)中的方向传感器的参数不同而改变显示的方向, ...
- wxWidgets刚開始学习的人导引(3)——wxWidgets应用程序初体验
wxWidgets刚開始学习的人导引全文件夹 PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wx ...
- Hadoop-2.2.0中文文档—— Common - CLI MiniCluster
目的 使用 CLI MiniCluster, 用户能够简单地仅仅用一个命令就启动或关闭一个单一节点的Hadoop集群,不须要设置不论什么环境变量或管理配置文件. CLI MiniCluster 同一时 ...