Xtu summer individual 1 e-palindromic numbers

Source: Internet
Author: User
E-palindromic numbers

Time limit:2000 msMemory limit:32768kb64bit Io format:% LLD & % LlU

 

Description

A palindromic number or numeral palindrome is a 'invalid rical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integersI j, You have to find the number of palindromic numbersIAndJ(Aggressive ).

 

 

Input

Input starts with an integerT (≤ 200), Denoting the number of test cases.

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

 

 

Output

For each case, print the case number and the total number of palindromic numbersIAndJ(Aggressive ).

 

 

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

 

Solution: Enter the number in the text box. It can be divided into two types: one is the length of an odd number, and the other is the length of an even number.

 

For example...

 

20 is a length of 2 and an even number. If you want to enumerate DP [1] [2] + d [1], what does it mean? D [1] is the number of input numbers with a length of 1! DP [1] [2] indicates the number of return numbers starting with 1 and with a length of 2.

 

Let's talk about 120 .. Enumeration d [2]: because it is an odd number, there is only one digit at the end. This is as long as the middle of the enumeration is done. Set the low position to the same as the high position, 1x1. Only X is enumerated starting from 0. As long as the value is still within the range of 120, one enumeration is incremented. Once the value is not within the range of 120, the loop jumps out immediately.

 

Let's say the length of an even number is 1234... D [3] + dp [0] [2] + dp [1] [2]. After the low position is consistent with the high position, 1221 is used to determine whether the number is within 1234, yes, just add one. If not, add 0. If you add 0, then do not add. You win !!!!!!

 

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cstdlib> 5 # include <vector> 6 # include <climits> 7 # include <algorithm> 8 # include <cmath> 9 # define ll long long10 # define INF 0x3f3f11 using namespace STD; 12 ll DP [200] [1000], d [200]; 13 int Len, bit [1000]; 14 void Init () {15 int I, J; 16 For (I = 0; I <10; I ++) 17 DP [I] [1] = DP [I] [2] = 1; 18 For (I = 3; I <20; I ++) {19 for (j = 0; j <10; j ++) {20 DP [J] [I] = 10 * DP [0] [I-2]; 21} 22} 23 d [0] = 1; // starts with 0... 0 is 24 for (I = 1; I <20; I ++) {25 for (j = 1; j <10; j ++) 26 d [I] + = DP [J] [I]; 27 d [I] + = d [I-1]; 28} // calculate the number of all input numbers 0-length I 29} 30 ll go (int e) {31 if (E <0) return 1; 32 ll sum = 0; 33 for (INT I = 0; I <10; I ++) {34 sum + = DP [I] [E]; 35} 36 return sum; 37} 38 ll CAL (ll n) {39 if (n <10) return n + 1; 40 ll x = N, ANS = 0, y = 0; 41 int I, J, K, V, U; 42 for (LEN = 0; X/= 10, Len ++) 43 bit [Len] = x % 10; 44 ans + = d [len-1]; 45 for (j = 0, V = Len> 1, I = len-1; i> = V; I --, J ++) {46 if (I = len-1) {47 for (k = 1; k <bit [I]; k ++) 48 ans + = DP [k] [Len]; 49} else if (I = J) {50 U = I; break; 51} else {52 for (k = 0; k <bit [I]; k ++) 53 ans + = DP [k] [Len-J * 2]; 54} 55} 56 if (I = J) {// odd length, the final result is influenced by the middle of the 57 for (I = 0, j = len-1; I <j; I ++, j --) 58 bit [I] = bit [J]; 59 for (k = 0; k <10; k ++) {60 bit [u] = K; 61 for (y = I = 0; I <Len; I ++) 62 y = y * 10 + bit [I]; 63 If (Y <= N) ans ++; 64 else break; 65} 66} else {// an even length, the final result is influenced by the last bit 67 for (I = 0, j = len-1; I <j; I ++, j --) 68 bit [I] = bit [J]; 69 for (y = I = 0; I <Len; I ++) 70 y = y * 10 + bit [I]; 71 If (Y <= N) ans ++; 72} 73 return ans; 74} 75 int main () {76 Init (); 77 int T, Ks = 1; 78 ll A, B, C; 79 scanf ("% d", & T); 80 while (t --) {81 scanf ("% LLD", & A, & B ); 82 If (A> B) Swap (a, B); 83 printf ("case % d: % LLD \ n", KS ++, Cal (B) -Cal (A-1); 84} 85 return 0; 86}
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.