主题链接: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语言入门(15)——结构体与数据抽象

    大多数的计算机运算是对现实世界的模拟,如果想用计算机来模拟现实世界需要用到数据抽象的方法.所谓抽象是从实际的人.物.事和概念中抽取所关心的共同特征,,忽略非本质的细节,吧这些特征用各种概念精确的加以描 ...

  2. linux备份mysql数据库

    刚学的技术,保存一下 1. 在linux服务器上创建一个 msyql.sh文件 (随便定义) ,用来保存备份mysql数据的脚本 2. 编辑mysql.sh文件   (自己之前写过的一个脚本) mys ...

  3. jquery 中 fn.apply(this, arguments)是什么函数?有什么作用?能举个例子吗

    function Person(name){ this.name=name; this.sayname=function (){ alert(this.name); } } function Stud ...

  4. magento中取不同store中的产品数据

    $products = Mage::getResourceModel('catalog/product_collection')                    ->setStoreId( ...

  5. JavaScript 的DOM操作

    HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. Windows 对象操作 ...

  6. box-shadow属性

    一.定义和用法 box-shadow属性 向框添加一个或多个阴影. 二.语法 box-shadow: h-shadow v-shadow blur spread color inset; h-shad ...

  7. SQL Server执行计划那些事儿(2)——查找和扫描

    接下来的文章是记录自己曾经的盲点,同时也透漏了自己的发展历程(可能发展也算不上,只能说是瞎混).当然,一些盲点也在工作和探究过程中慢慢有些眉目,现在也愿意发扬博客园的奉献精神,拿出来和大家分享一下. ...

  8. ios 应用程序之间的跳转(内置程序的实现)

    ios 应用程序之间的跳转(内置程序的实现) 一个程序若要跳到另一个程序.需要在目标程序的plist文件里面修改: 打开info.plist,添加一项URL types 展开URLtypes,再展开I ...

  9. Android RadioGroup/RadioButton

    RadioGroup      RadioButton的集合,提供多选一的机制      属性:   android:orientation="horizontal/vertical&quo ...

  10. nodejs 文件查找中文,替换为英文

    帮以前同事解决一个需求,中文项目 翻译 英文项目~~~ 考虑到具体实现方面的问题,如果智能的话,肯定是要做中文的语法分析,不过感觉这个有难度. 所以最后的方案是遍历文件,将中文短语匹配出来,再进行人工 ...