hdu 5062(水题)

Beautiful Palindrome Number

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1067    Accepted Submission(s): 691


Problem Description
A positive integer x can represent as (a1a2akaka2a1)10 or (a1a2ak1akak1a2a1)10 of a 10-based notational system, we always call x is a Palindrome Number. If it satisfies 0<a1<a2<<ak9, we call x is a Beautiful Palindrome Number.
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and 10N.
 

 

Input
The first line in the input file is an integer T(1T7), indicating the number of test cases.
Then T lines follow, each line represent an integer N(0N6).
 

 

Output
For each test case, output the number of Beautiful Palindrome Number.
 

 

Sample Input
2 1 6
 

 

Sample Output
9 258
 

 

Source
 
打表模拟
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
/*void init(int test)
{
    int n = 1;
    for(int i=1; i<=test; i++)
    {
        n*=10;
    }
    int a[10],cnt=0;
    for(int i=1; i<=n; i++)
    {
        int m = i;
        int id = 1;
        while(m)
        {
            a[id++] = m%10;
            m/=10;
        }
        bool flag = true;
        for(int k=1,j=id-1; k<=j; k++,j--)
        {
            if(a[k]!=a[j])
            {
                flag = false;
                break;
            }
        }
        if(flag)
        {
            id = id-1;
            flag = true;
            for(int k=2; k<=id/2; k++)
            {
                if(a[k]<=a[k-1]) flag = false;
            }
            if(id%2==1&&id!=1){
                if(a[id/2]>=a[id/2+1]) flag = false;
            }
            if(flag) {
                printf("%d\n",i);
                cnt++;
            }
        }
    }
    printf("%d\n",cnt);
}*/
int a[]={1,9,18,54,90,174,258};
int main()
{
    /*int test;
    while(true){
    scanf("%d",&test);
    init(test);
    }*/
    int tcase;
    scanf("%d",&tcase);
    while(tcase--){
        int n;
        scanf("%d",&n);
        printf("%d\n",a[n]);
    }
    return 0;
}

 

posted @ 2016-07-09 22:25  樱花庄的龙之介大人  阅读(174)  评论(0编辑  收藏  举报