hdu 5062 Beautiful Palindrome Number(Bestcodeer Round #13)

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 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.

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).

Output

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

Sample Input

2
1
6

Sample Output

9
258

Source

BestCoder Round #13

结果就只有七个,交上去一个表就行了,n最大为6,暴力代码也能过。附上打表代码和暴力代码。

打表代码:

//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]);
    }
}

暴力代码:

//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;
}

时间: 2024-10-11 06:05:55

hdu 5062 Beautiful Palindrome Number(Bestcodeer Round #13)的相关文章

HDU 5062 Beautiful Palindrome Number(数学)

主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 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<

HDU 5063 Operation the Sequence(BestCoder Round #13)

Problem Description: You have an array consisting of n integers: a1=1,a2=2,a3=3,…,an=n. Then give you m operators, you should process all the operators in order. Each operator is one of four types:Type1: O 1 call fun1();Type2: O 2 call fun2();Type3:

HDU 4932 Miaomiao&#39;s Geometry(BestCoder Round #4)

Problem Description: There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length. There are 2 limits: 1.A point is convered if there is a segments T , the point is the left end or the right end of T.2.The le

Palindrome Number (回文数)

回文数是指这样的数字:正读和倒读都是一样的.如:595,2332都是回文数,234不是回文数. 注意:负数不是回文数 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string

HDU 1394——Minimum Inversion Number(最小逆序数)

题意: 给定一个序列,里面的数是0到n-1,  每次要把第一个数放到最后一个数,重复n次,求n次操作中最小的逆序数是多少? 思路: 先求出初始的逆序数,然后每移动第一个数到最后面,那么逆序数要减去比它小的数的个数,加上比它大的数的个数. 如果我输入的数是a[i],那么比它小的数的个数就有a[i]个,比它大的数的个数就有n-1-a[i]个 方法:    归并排序 ,树状数组,线段树 归并排序代码: #include<iostream> #include<cstring> #inclu

HDU 1394 Minimum Inversion Number (数据结构-线段树)

Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9514    Accepted Submission(s): 5860 Problem Description The inversion number of a given number sequence a1, a2, ..., an

LeetCode 9 Palindrome Number (回文数)

翻译 确定一个整数是否是回文数.不能使用额外的空间. 一些提示: 负数能不能是回文数呢?(比如,-1) 如果你想将整数转换成字符串,但要注意限制使用额外的空间. 你也可以考虑翻转一个整数. 然而,如果你已经解决了问题"翻转整数(译者注:LeetCode 第七题), 那么你应该知道翻转的整数可能会造成溢出. 你将如何处理这种情况? 这是一个解决该问题更通用的方法. 原文 Determine whether an integer is a palindrome. Do this without ex

HDU - 5210 - Delete &amp;&amp; 5211 - Mutiple (BestCoder Round #39)

题目传送:HDU - 5210 HDU - 5210 - Delete 思路:简单题 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <vector> #include &l

HDU 4883 TIANKENG’s restaurant(BestCoder Round #2)

Problem Description: TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come to enjoy their meal, and there are Xi persons in the