HDU 5062 beautiful palindrome number (mathematical problem)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 5062


Problem descriptiona positive integer x can represent (A1a2... Akak... A2a1) 10 Or (A1a2... AK? 1 Akak? 1... A2a1) 10 Of a 10-based notational system, we always call X is a palindrome number. If it satisfies 0 <A1 <A2 <... <Ak ≤ 9 , We call X is a beautiful palindrome number.
Now, we want to know how many beautiful palindrome numbers are between 1 and 10n . Inputthe first line in the input file is an integer T (1 ≤ T ≤ 7) , Indicating the number of test cases.
Then T lines follow, each line represent an integer N (0 ≤ n ≤ 6) . Outputfor each test case, output the number of beautiful palindrome number. sample input
216
Sample output
9258
Sourcebestcoder round #13


Question:

Within the range of the N power from 1 to 10, the following conditions are met:

1. It is the number of replies;

2. The first half of the text is in ascending order;


Code for table creation:

# 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 ++) // return {if (a [I]! = A [L-I + 1]) return 0 ;}for (INT I = 1; I <l/2 + L % 2; I ++) // in ascending order {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 <= 10) sum [1] ++; if (I <= 100) sum [2] ++; if (I <= 1000) 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;}


HDU 5062 beautiful palindrome number (mathematical problem)

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.