Little Elephant and Interval
来源:互联网 发布:医疗软件销售 编辑:程序博客网 时间:2024/04/28 15:19
Description
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l andr(l ≤ r). The Little Elephant has to find the number of such integersx(l ≤ x ≤ r), that the first digit of integerx equals the last one (in decimal notation). For example, such numbers as101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pairl and r.
Input
The single line contains a pair of integers l andr(1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to usecin, cout streams or the%I64d specifier.
Output
On a single line print a single integer — the answer to the problem.
Sample Input
2 47
12
47 1024
98
Hint
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
意思就只求区间内M ~ N内的首尾和末位数字相同的个数
任然采用0~N区间的数字 减去 0~M 区间的数字个数
对于数字N ,如果小于10,然么直接返回。 要不然返回首尾的数字加上9.而且要注意当首尾大于末位的时候,需要减一
举个例子:46这个数。一共有1~9 加上11,22,33,44.这4个数一共13个数符合题目要求,正好是n / 10 + 9.
当数字为43时,首尾大于末位,44这样的数字就不符合要求了。所以当首尾大于末位时需要sum--;
/*********************************************** * Author: fisty * Created Time: 2015/2/8 20:47:21 * File Name : 6_D.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)LL solve(LL n){ LL sum = 0; if(n < 10) return n; else{ int r = n % 10; sum = n / 10 + 9; while(n >= 10) n /= 10; //Debug(sum); if(n > r) sum--; } //Debug(sum); return sum;}int main(){ //freopen("in.cpp", "r", stdin); cin.tie(0); ios::sync_with_stdio(false); LL l, r; cin >> r >> l; cout << solve(l) - solve(r-1) << endl; return 0;}
- Little Elephant and Interval
- A. Little Elephant and Interval
- codeforces 204A Little Elephant and Interval
- codeforce 205C - Little Elephant and Interval
- CodeForces 204A Little Elephant and Interval
- CodeForces 204A Little Elephant and Interval
- Codeforces Round #129 (Div. 1) A Little Elephant and Interval
- codeforces 204A Little Elephant and Interval (数位dp)
- CodeForces 204A Little Elephant and Interval 数位DP
- CF 205 C Little Elephant and Interval(模拟)
- Codeforces 204A Little Elephant and Interval(数位DP)
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
- Codeforces 204A Little Elephant and Interval(数位统计)
- Little Elephant and Function
- Little Elephant and Problem
- Little Elephant and Mouses
- CodeForces 204A - Little Elephant and Interval 算答案..易错..暴力打表对拍
- codeforces CodeForces 204A Little Elephant and Interval (数位dp简单)
- NDK(Native Development Kit)文档:入口
- Microsoft Windows Azure 提供了哪些服务(续)
- C++ Primer(第4版)-第1部分:基本语言——学习笔记
- Linearlayout
- 第19周上机时间项目4——点和距离
- Little Elephant and Interval
- javascript-6函数
- hdu 4554 叛逆的小明
- Install Mysql MMM On Redhat6.3
- MFC单文档 取消标题栏,取消窗口边框,取消菜单栏, 取消莫名其妙的样式
- 看数据结构写代码(4)单链表
- C++ Primer(第4版)-第2部分:容器和算法——学习笔记
- OC 中快速枚举器简单讲解.
- php合成照片