主题链接: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. [WPF]解决ListView在没有Items时,水平滚动条不出现的问题

    转载地址:http://www.cnblogs.com/nankezhishi/archive/2010/03/19/FixListViewNotScrollHeaderBug.html 在上一篇Bl ...

  2. 实现拦截API的钩子(Hook)

    道理不多讲,简单说就是将系统API的跳转地址,替换为我们自己写的API的地址,所以要求我们自定义的API函数要和被拦截的API有相同的参数.在用完后,记得恢复. 因为要挂全局的钩子,所以Hook的部分 ...

  3. android支付宝支付开发过程

    原文:android支付宝支付开发过程 支付宝开发流程: 1.在支付宝申请一个账号并开通开发者功能和移动支付的功能. 支付宝地址:https://auth.alipay.com/login/index ...

  4. node.js介绍

    官网说明: Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable ...

  5. SMO要点总结

    SMO要点总结: SMO使用坐标上升的方法,求解SVM的最优解.和原始坐标上升方法的不同点在于: 1.       由于SVM的限制条件 ,所以不能只使用一个坐标,改为更新两个 2.       采用 ...

  6. Apache HTTP Server

    下载 http://rj.baidu.com/soft/detail/14824.html?ald 安装完成后,打开浏览器,输入http://localhost/ 如果显示: It works! 则代 ...

  7. 《github一天一道算法题》:插入排序

    看书.思考.写代码! /*********************************************** * copyright@hustyangju * blog: http://bl ...

  8. Freedur为什么会免费?

    难道没人看看他们的官方站点吗? Freedur倒闭了...... 一个中国人,Chris Lee,作为Freedur的会计师,窃取了公司的银行帐号.并将Freedur的官方站点指向自己的空间.而且声称 ...

  9. SharePoint webpart中悬浮窗口的webconfig路径

    SharePoint webpart中悬浮窗口的webconfig路径在.../_layouts/15/下.

  10. jquery ajax 参数可以序列化

    <form> <input type="text" name="FirstName" value="Bill" /> ...