主题链接: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

题意:

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

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

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5062 题目意思:给出 N,找出 1 - 10^N 中满足 Beautiful Palindrome N ...

  2. hdu 5062

    题意:将10^0-10^6之间属于  "Beautiful Palindrome Number" 的数个数打印出来,所谓 "Beautiful Palindrome Nu ...

  3. hdu 5062(水题)

    Beautiful Palindrome Number Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  4. 有趣的数-回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  5. hdu 6216 A Cubic number and A Cubic Number【数学题】

    hdu 6216 A Cubic number and A Cubic Number[数学] 题意:判断一个素数是否是两个立方数之差,就是验差分.. 题解:只有相邻两立方数之差才可能,,因为x^3-y ...

  6. 有趣的回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  7. 65. Reverse Integer && Palindrome Number

    Reverse Integer Reverse digits of an integer. Example1: x =  123, return  321 Example2: x = -123, re ...

  8. 9. Palindrome Number

    /* Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers ...

  9. No.009 Palindrome Number

    9. Palindrome Number Total Accepted: 136330 Total Submissions: 418995 Difficulty: Easy Determine whe ...

随机推荐

  1. js返回当前时间的毫秒数

    Date.now(); +new Date(); new Date().getTime();

  2. Windows 7安装教程(详细图解)

    早前向大家介绍了Windows XP的安装教程,今天思齐再来介绍一下Windows 7的安装教程,Windows 7在安装上相对以前的Windows操作系统都要简单一些,这一点对于尤其是非专业用户来说 ...

  3. EventBus源码解析

    用例 本文主要按照如下例子展开: //1. 新建bus对象,默认仅能在主线程上对消息进行调度 Bus bus = new Bus(); // maybe singleton //2. 新建类A(sub ...

  4. ORACLE RAC中的oc4j和gsd资源以及RAC相关的进程

    1.RAC相比单实例数据库多出的进程: LMS - Gobal Cache Service Process 全局缓存服务进程 LMD - Global Enqueue Service Daemon 全 ...

  5. sparse autoencoder

    1.autoencoder autoencoder的目标是通过学习函数,获得其隐藏层作为学习到的新特征. 从L1到L2的过程成为解构,从L2到L3的过程称为重构. 每一层的输出使用sigmoid方法, ...

  6. 从头开始-02.C语言基础

    变量的内存分析: #include <stdio.h> int main() { //内存地址由大到小 int a=10; int b=20; //&是一个地址运算符,取得变量的地 ...

  7. 常用的sql server规范

    常见的字段类型选择1.字符类型建议采用varchar/nvarchar数据类型2.金额货币建议采用money数据类型3.科学计数建议采用numeric数据类型4. 自增长标识建议采用bigint数据类 ...

  8. 关闭Sql Assistant的自动智能命名别名的问题

    关于SQL Assistant在编写比如SELECT * FROM UserInfo AS ui  会自动给表命名一个别名的问题,有时候这个很烦, 点开Options,选项卡DB Options,左侧 ...

  9. JS前端知识模块大全

    公司前端:小胖提供,表示感谢 1. 基础 HTML, CSS, JS 文档 W3CSCHOOL: http://www.w3schools.com/ MDN: https://developer.mo ...

  10. java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils

    页面报错: root: java.lang.NoClassDefFoundError: Could not initialize class net.sf.json.util.JSONUtils 出错 ...