Topics Link: http://acm.hdu.edu.cn/showproblem.php?
pid=5062
Problem Descriptiona positive integer x can represent as ( a 1 a 2 ... .. a k a k ... .. a 2 a 1 ) ten Or ( a 1 a 2 ... .. ak? 1 a k ak? 1 ... .. a 2 a 1 ) ten of a 10-based notational system, we always call X is a palindrome number. If it satisfies 0< a 1 < a 2 <... ..< a k ≤9 , we call X is a Beautiful palindrome number.
Now, we want to know how many Beautiful palindrome Numbers is between 1 and tenN . Inputthe first line in the input file was an integer < Span class= "Mrow" id= "mathjax-span-93" style= "" >t 1 ≤ T ≤ 7 ) , indicating the number of test cases.
Then T-lines follow, each line represent an integer < Span class= "Mrow" id= "mathjax-span-103" style= "" >n 0 n ≤ 6 " . Outputfor each test case, output the number of Beautiful palindrome number. Sample Input
216
Sample Output
9258
Sourcebestcoder Round #13
Test instructions
In the range of 1 to 10 of the N-square, satisfy:
1, is a palindrome number;
2, the first half of the palindrome to meet the ascending.
To play the table code:
#include <cstdio> #include <cstring>int find_num (int num) {int a[17]; memset (A,0,sizeof (a)); int L = 0; while (num) {a[++l] = num%10; num/=10; } for (int i = 1; I <= L/2; i++)//palindrome {if (a[i]! = a[l-i+1]) return 0; } for (int i = 1; i < l/2+l%2; i++)//Ascending {if (a[i+1] <= a[i]) return 0; } return 1;} int main () {int sum[17]; memset (sum,0,sizeof (sum)); Sum[0] = 1; for (int i = 1; I <= 1000000; i++) {int flag = Find_num (i); if (flag) {//printf ("num::%d\n", I); if (i <=) sum[1]++; if (i <=) sum[2]++; if (i <=) sum[3]++; if (I <= 10000) sum[4]++; if (i <= 100000) sum[5]++; if (i <= 1000000) sum[6]++; }} int t; for (int i = 0; I <= 6; i++) { printf ("%d::%d\n", I,sum[i]); } return 0;}
The code is as follows:
#include <cstdio>int main () { int t; scanf ("%d", &t); while (t--) { int n; scanf ("%d", &n); if (n = = 0) printf ("1\n"); else if (n = = 1) printf ("9\n"); else if (n = = 2) printf ("18\n"); else if (n = = 3) printf ("54\n"); else if (n = = 4) printf ("90\n"); else if (n = = 5) printf ("174\n"); else if (n = = 6) printf ("258\n"); } return 0;}
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
HDU 5062 Beautiful palindrome number (math)