主题链接: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. C++vptr初始化时间

    给出如下代码段: #include <iostream> #include "stdio.h" using namespace std; class A { publi ...

  2. Azure 为 SAP 提供的增强监控解决方案

    正如大家在之前公告中所看到的,多个SAP应用程序已获得认证可在 Azure虚拟机中运行,未来还会有更多 SAP应用程序获得认证.对于希望在 Azure中运行 SAP应用程序的客户来说,这是个激动人心的 ...

  3. 关于我们-成功人士西装定制服务第一品牌派斯特PAISTETAILOR绅士礼服

    关于我们-成功人士西装定制服务第一品牌派斯特PAISTETAILOR绅士礼服 北京派思特服装服饰有限公司国内领先绅士男装定制品牌PAISTETAILOR,引领男装定制的领航者.

  4. 查询无序列表中第K小元素

    当需要在无需列表中寻找第k小的元素时,一个显然的方法是将所有数据进行排序,然后检索k个元素.这种方法的运行时间为O(n log(n)). 无序列表调用分区函数将自身分解成两个子表,其长度为i和n-i. ...

  5. dhtmlgrid修改,支持IE10

    因为项目IE升级,导致原来使用的dhtmlgrid无法正常显示,同时通过loadxml接口还有属性不支持. 花了半天时间对dhtmlgrid进行了修改,能够支持IE10正常加载显示. edit by ...

  6. MySQL- 锁机制及MyISAM表锁

    锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源(如CPU.RAM.I/O等)的争用以外,数据也是一种供许 多用户 共享的资源.如何保证数据并发访问的一致性.有效性是所 ...

  7. 密码算法详解——Simon

    0 Simon简介 详细文档请直接阅读参考文献[1]. Simon是由NSA设计的轻量级分组密码算法(LIGHTWEIGHT BLOCK CIPHER).主要应用于硬件或软件条件受限(例如:芯片面积要 ...

  8. 我终于解决UM编辑器了 泪......

    气死我了..... 好不容易测试好了....更显得我笨了..... 原来....什么都不用改   只改了2个小位置....真的是.....回首自己 不敢看 0.0 OK  记下步骤  以免以后忘记 将 ...

  9. js charts去掉logo

    打开js charts 3的源代码搜索关键字"fs.bg",然后会找到 fs.bg.2v(fX),将这句代码删掉就OK了,可能有的版本会是fs.bg.2u(fX) 欢迎加入群:25 ...

  10. Oracle EBS使用adpatch工具打patch过程【Z】

    Oracle EBS使用adpatch工具打patch过程 从Metalink下载补丁 登陆到Metalink(https://support.oracle.com),Oracle内部用户可以使用AR ...