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

题意:

求1到10的n次方的范围内,满足:

1、是回文数;

2、回文的前半部分满足升序。

打表代码:

#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++)//回文
    {
        if(a[i] != a[L-i+1])
            return 0;
    }
    for(int i = 1; i < L/2+L%2; i++)//升序
    {
        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;
}

代码例如以下:

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

版权声明:本文博主原创文章。博客,未经同意不得转载。

时间: 2024-08-25 21:57:56

HDU 5062 Beautiful Palindrome Number(数学)的相关文章

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

BestCoder13 1001.Beautiful Palindrome Number(hdu 5062) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5062 题目意思:给出 N,找出 1 - 10^N 中满足 Beautiful Palindrome Numbers (BPN)的数量有多少. 满足 BPN 的条件有两个:(1)回文串   (2)对称的部分从左到右递增排放. (1)版本 1 (比较麻烦,建议看版本2)        46ms 1 #include <iostream> 2 #include <cstdio> 3 #inc

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 (a1a2…akak…a2a1)10 or (a

HDU 4937 Lucky Number (数学,进制转换)

题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last); //把[first0,last0)之间的部分替换成[first,last)之间的字符串 /* 题意: 我们将3,4,5,6认为是幸运数字.给定一个十进制数n. 现在可以讲起任意转

HDU 1018 Big Number 数学题解

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of

hdu 6216 A Cubic number and A Cubic Number【数学】

hdu 6216 A Cubic number and A Cubic Number 题意:判断一个素数是否是两个立方数之差,就是验差分. 题解:只有相邻两立方数之差才可能,,因为x^3-y^3=(x-y)(x^2+xy+y^2),看(x-y),就能很快想到不相邻的立方数之差是不可能是素数的:),,然后把y=x+1代入,得:p=3x^2+3x+1,所以可得判断条件为:①p-1必须能被3整除:②(p-1)/3必须能表示为两个相邻整数之积. 1 #include<iostream> 2 #incl

leetcode_9题——Palindrome Number (数学问题)

Palindrome Number Total Accepted: 57795 Total Submissions: 194286My Submissions Question Solution Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Hide Tags Math Have you met this question in a real i

hdu 5623 KK&#39;s Number(dp)

问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗10?4??)个数,每次KK都会先拿数.每次可以拿任意多个数,直到NN个数被拿完.每次获得的得分为取的数中的最小值,KK和对手的策略都是尽可能使得自己的得分减去对手的得分更大.在这样的情况下,最终KK的得分减去对手的得分会是多少? 输入描述 第一行一个数T\left( 1\leq T\leq 10\right)T(1≤T≤10),表示数据组

hdu 1115 Lifting the Stone (数学几何)

Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5203    Accepted Submission(s): 2155 Problem Description There are many secret openings in the floor which are covered by a big