Beautiful Palindrome Number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1062 Accepted Submission(s): 688
Problem Description
A positive integer x can represent as
(a1a2…akak…a2a1)10
or
(a1a2…ak−1akak−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 .
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(1≤T≤7)
, indicating the number of test cases.
Then T lines follow, each line represent an integer N(0≤N≤6) .
Then T lines follow, each line represent an integer N(0≤N≤6) .
Output
For each test case, output the number of Beautiful Palindrome Number.
Sample Input
2 1 6
Sample Output
9 258
思路:直接模拟,当然像我这样打表也行,n只有6
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
/*int a[10];
int check(int x)
{
int l=x,ans=0;
int num=0;
while(l)
{
ans=ans*10+l%10;
l/=10;
num++;
}
if(ans!=x) return 0;
if(num&1) num++;
num/=2;
int now=-1;
while(num--)
{
int w=x%10;
if(w<=now) return 0;
now=w;
x/=10;
}
return 1;
}
void init()
{
int num=0;
for(int i=1;i<=100;i++)
{
if(check(i))
num++;
}
printf("%d\n",num);
}*/
int main()
{
int T,n;
//init();
scanf("%d",&T);
while(T--)
{
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 printf("258\n");
}
return 0;
}