E - Palindromic Numbers

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integers i j, you have to find the number of palindromic numbers between i and j (inclusive).

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case starts with a line containing two integers i j (0 ≤ i, j ≤ 1017).

Output

For each case, print the case number and the total number of palindromic numbers between i and (inclusive).

Sample Input

4

1 10

100 1

1 1000

1 10000

Sample Output

Case 1: 9

Case 2: 18

Case 3: 108

Case 4: 198

解题:回文数字。分成两种类型判断,一种是长度为奇数个的,一种是长度为偶数个的。

举个栗子。。。

20 是长度为2的,偶数长度,只要枚举dp[1][2]+d[1]什么意思呢?d[1]就是长度为1 的回文数字有多少个!dp[1][2]表示以1开始,长度为2的回文数字的个数。

再说120.。枚举d[2],由于是奇数,最后是遇到只有一个数字的情况,这是只要枚举最中间这一位就可以了,把低位与高位设置成一致的,1x1,只有从0开始枚举x,只要还在120的范围内,每枚举一个就加一,一旦不在120的范围内立即跳出循环。

再说一个偶数的长度1234.。。d[3]+dp[0][2]+dp[1][2],把低位跟高位一致后,1221,判断这个数是不是在1234内,是就加一,不是就加0,好吧加0就是不加,你赢了!!!!!!

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
LL dp[][],d[];
int len,bit[];
void init() {
int i,j;
for(i = ; i < ; i++)
dp[i][] = dp[i][] = ;
for(i = ; i < ; i++) {
for(j = ; j < ; j++) {
dp[j][i] = *dp[][i-];
}
}
d[] = ;//以0开始的。。。0就是
for(i = ; i < ; i++) {
for(j = ; j < ; j++)
d[i] += dp[j][i];
d[i] += d[i-];
}//算出0-长度为i的所有回文数字数目
}
LL go(int e) {
if(e < ) return ;
LL sum = ;
for(int i = ; i < ; i++) {
sum += dp[i][e];
}
return sum;
}
LL cal(LL n) {
if(n < ) return n+;
LL x = n,ans = ,y = ;
int i,j,k,v,u;
for(len = ; x; x /= , len++)
bit[len] = x%;
ans += d[len-];
for(j = ,v = len>>,i = len-; i >= v; i--,j++) {
if(i == len-) {
for(k = ; k < bit[i]; k++)
ans += dp[k][len];
} else if(i == j) {
u = i;break;
} else {
for(k = ; k < bit[i]; k++)
ans += dp[k][len-j*];
}
}
if(i == j) {//奇数个长度,最后结果受最中间的那位影响
for(i = ,j = len-; i < j; i++,j--)
bit[i] = bit[j];
for(k = ; k < ; k++){
bit[u] = k;
for(y = i = ; i < len; i++)
y = y*+bit[i];
if(y <= n) ans++;
else break;
}
}else{//偶数个长度,最后结果受最后一位影响
for(i = ,j = len-; i < j; i++,j--)
bit[i] = bit[j];
for(y = i = ; i < len; i++)
y = y*+bit[i];
if(y <= n) ans++;
}
return ans;
}
int main() {
init();
int t,ks = ;
LL a,b,c;
scanf("%d",&t);
while(t--){
scanf("%lld %lld",&a,&b);
if(a > b) swap(a,b);
printf("Case %d: %lld\n",ks++,cal(b)-cal(a-));
}
return ;
}

xtu summer individual 1 E - Palindromic Numbers的更多相关文章

  1. xtu summer individual 1 D - Round Numbers

    D - Round Numbers Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u D ...

  2. LightOJ 1205 Palindromic Numbers

    数位DP.... Palindromic Numbers Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %l ...

  3. Lightoj1205——Palindromic Numbers(数位dp+回文数)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  4. LightOJ - 1396 :Palindromic Numbers (III)(逐位确定法)

    Vinci is a little boy and is very creative. One day his teacher asked him to write all the Palindrom ...

  5. LightOJ - 1205:Palindromic Numbers (数位DP&回文串)

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  6. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  7. xtu summer individual 4 C - Dancing Lessons

    Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  8. xtu summer individual 2 E - Double Profiles

    Double Profiles Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  9. xtu summer individual 2 D - Colliders

    Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

随机推荐

  1. 洛谷 P1199 三国游戏

    参考:Solution_ID:17 题解 更新时间: 2016-11-13 21:01 这道题要求最后得到的两方的默契值最大的武将,小涵的默契值大于计算机,首先,我们这个解法获胜的思路是,每个武将对应 ...

  2. 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

    题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...

  3. 因磁盘空间不足导致HDFS的NameNode进入安全模式问题记录

    因磁盘空间不足导致HDFS的NameNode进入安全模式问题记录,调用API上传及下载文件时报如下错误信息: org.apache.hadoop.ipc.RemoteException(org.apa ...

  4. 127 Word Ladder 单词接龙

    给出两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列,转换需遵循如下规则:    每次只能改变一个字母.    变换过程中的 ...

  5. Jenkins视图使用--添加删除视图

    job建立的特别多的时候,我们可能不太容易找到自己的某个job,这时,我们就可以在Jenkins中建立视图.job的视图类似于我们电脑上的文件夹.可以通过一些过滤规则,将已经建好的job过滤到视图中, ...

  6. 关于ES6的Promise的使用深入理解

    ES6的promise对象研究 什么叫promise? Promise对象可以理解为一次执行的异步操作,使用promise对象之后可以使用一种链式调用的方式来组织代码:让代码更加的直观. 那我们为什么 ...

  7. Excuse me?这个前端面试在搞事!

    金三银四搞事季,前端这个近年的热门领域,搞事气氛特别强烈,我朋友小伟最近就在疯狂面试,遇到了许多有趣的面试官,有趣的面试题,我来帮这个搞事 boy 转述一下. 以下是我一个朋友的故事,真的不是我. f ...

  8. BOM学习-javascript计时器小结

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  9. IOS状态栏

    IOS状态栏是什么地方? 它是IOS设备屏幕顶部显示信号以及电池的区域.状态栏默认的高度是20像素,状态栏在软件开发中有何作用?联网应用中可在自动帮用户下载数据时使用,推荐在状态栏中予以显示.状态栏可 ...

  10. 【HEVC简介】High Level Syntax

    参考文献:见<High Efficiency Video Coding (HEVC)>High Level Syntax章节 <HEVC标准介绍.HEVC帧间预测论文笔记>系列 ...