主题链接: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. 假数据自我添加测试--NSArray object

    一.列表假数据 //在.h文件里面定义node所包含实体类---1 struct listTestNode { NSString *image; NSString *name; }; //在.m实现文 ...

  2. MAC 下使用ipv6、ipv4观看电视、网络电视

      换了mac book,ipv6电视却看不了了,为了看电视,只要自己动手了. 关于ipv6是啥和哪里有ipv6这里就不说了,找度娘吧. 我们观看IPv6视频直播信号有两种,一种是mms协议,另外一种 ...

  3. POJ1007

    2014-08-22   题目意思: 按照各个字符串的逆序数排序(稳定排序,即若A=B,则AB的顺序还是原来的样子) 思路: 求出每个字符串的逆序数后,排序输出即可 代码: //Memory Time ...

  4. Linux是什么

    计算机主要以二进制为单位,而目前常用的磁盘容量单位为B,其单位换算为1B=8bit,其他的以1024为其倍数,如1GB=1024MB等. 操作系统(Operation System)主要用于管理与驱动 ...

  5. 【Andord真】SlideMenu+ViewPagerIndictor双滑动边栏+滑动导航条

    采取SlideMenu达到的效果侧边栏: 间 setContentView是设置主背景的布局 setBehindContentView是设置左边菜单的布局 setSecondaryMenu是设置右边的 ...

  6. java中文乱码解决之道(四)—–java编码转换过程

    原文出处:http://cmsblogs.com/?p=1475 前面三篇博客侧重介绍字符.编码问题,通过这三篇博客各位博友对各种字符编码有了一个初步的了解,要了解java的中文问题这是必须要了解的. ...

  7. ACCESS 里面的坑

    在vs2005中用sql语句访问access数据库出现replace函数未定义错误,后来查询得知,在不能用replace访问access. 问题:   1.为什么以前运行正常的Access数据库,搬到 ...

  8. Java面试题之J2EE是什么

    J2EE是Sun公司提出的多层(multi-diered),分布式(distributed),基于组件(component-base)的企业级应用模型(enterpriese application ...

  9. 用PS绿化版出现“请卸载并重新安装该产品”的解决方法

    下载了一个CS6版本的绿化版PS,解压后发现用不了,因为是不用安装的,所以这个提示明显是没用的. 我把64位破解文件 amtlib.dll和32位破解文件 amtlib.dll都放进去试了一下,结果行 ...

  10. win32 消息说明

    WM_NULL = $0000; WM_CREATE = $0001; 应用程序创建一个窗口 WM_DESTROY = $0002; 一个窗口被销毁 WM_MOVE = $0003; 移动一个窗口 W ...