【CUGBACM15级BC第13场 A】hdu 5062 Beautiful Palindrome Number

70 篇文章 0 订阅

Beautiful Palindrome Number

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


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
 

题意:

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

1、是回文数;

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


///AC代码

/* ***********************************************
┆  ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓ 马 ┏━┛ ┆
┆  ┃ 勒 ┃  ┆      
┆  ┃ 戈 ┗━━━┓ ┆
┆  ┃ 壁     ┣┓┆
┆  ┃ 的草泥马  ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */
#include <iostream>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define inf 0x3f3f3f3f
#define debug(x) cout<<"---"<<x<<"---"<<endl
typedef long long ll;
using namespace std;


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)
        {
            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;
    scanf("%d", &t);
    while (t--)
    {
        int xx;
        scanf("%d", &xx);
        printf("%d\n", sum[xx]);
    }
    return 0;
}





/************************************************
┆  ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓    ┏━┛ ┆
┆  ┃    ┃  ┆      
┆  ┃    ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃           ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值