HDU 5062 beautiful palindrome number (bestcodeer round #13)

Source: Internet
Author: User

Beautiful palindrome number Time Limit: 3000/1500 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 116 accepted submission (s): 82


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
There are only seven results. Just hand in a table. The maximum number of N is 6, and the brute-force code is acceptable. Attach the tabulation code and brute force code.
Code for table creation:
//0ms#include <cstdio>#include <cstring>#include <iostream>int a[7]={1,9,18,54,90,174,258};int main(){    int t,n;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        printf("%d\n",a[n]);    }}

Brute force code:
//46ms#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[10];bool judge(int x){    int n=0;    while(x>0)    {        a[++n]=x%10;        x=x/10;    }    //printf("%d\n",n);    if(a[1]!=a[n])    return false;    for(int j=2,k=n-1;j<=k;j++,k--)    {        if(a[j]>a[j-1]&&a[j]==a[k])        ;        else        return false;    }    return true;}int main(){    int t,n;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        int temp=1;        int ans=0;        for(int i=1;i<=n;i++)        {            temp*=10;        }        //printf("%d",temp);        for(int i=1;i<=temp;i++)        {            if(judge(i))            {                ans++;            }        }        printf("%d\n",ans);    }    return 0;}


HDU 5062 beautiful palindrome number (bestcodeer round #13)

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.