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

是指一中回文串数字,比如123321或者12321,类似于这种的数........

分析:代码我是直接打表出来的,因为T<=7,N<=6,数据不大.....

AC代码:

#include <iostream>
using namespace std; int main()
{
int T,N;
int a[8] = {1,9,18,54,90,174,258};
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
printf("%d\n",a[N]);
}
return 0;
}

具体算法这里我贴下另外以为大神写的:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxn = 1000000+5; int f[maxn];
int huiwen(int n)//写一个回文函数
{
char array[10];
sprintf(array,"%d",n);//将整数N按%d的形式读入字符串中
int len = strlen(array);//求出字符串的长度
int flag = 1;//设置一个标志变量
if(len%2 == 0)
{
for(int j = 0; j < len/2; j++)//当长度为偶数时,j<len/2
{
if(array[0] != array[len-1] && j == 0)//因为该回文数的各个位是递增的,所以要判断每一位与前一位的大小关系,当j=0时,要特判
{
flag = 0; break;
}
if((array[j] != array[len-j-1] || array[j-1] >= array[j]) && j > 0)//当j>0时,要判断每一位与前一位的大小关系和len-j-1位置是否相等
{
flag = 0; break;
}
}
}
else
{
for(int j = 0; j <= len/2; j++)//当为奇数时,j <= len/2
{
if(array[j] != array[len-j-1] && j == 0)
{
flag = 0; break;
}
if((array[j] != array[len-j-1] || array[j-1] >= array[j]) && j > 0)
{
flag = 0; break;
}
}
}
if(flag) return 1;
else return 0;
} int main()
{
int T,N;
int sum = 0,cas = 0;
for(int i = 1; i < 1000001; i++)
{
sum +=huiwen(i);//sun直接对每个数返回的值进行累加,Beautiful回文越大的,sum自然也越大
if(huiwen(i))printf("%d %d\n",++cas,i);//可以输出每一个Beautiful回文数
f[i] = sum;
}
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
int temp = pow(10,N);
printf("%d",f[temp]);//直接输出
}
return 0;
}

hdu 5062的更多相关文章

  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 Beautiful Palindrome Number(数学)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...

  3. hdu 5062 单峰数(12321)的个数

    http://acm.hdu.edu.cn/showproblem.php?pid=5062 模拟筛出对称单峰数(12321)的个数,水题 #include <cstdio> #inclu ...

  4. hdu 5062(水题)

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

  5. HDU 4433 locker(12年天津,DP)

    4576 njczy2010 C Accepted 860 KB 140 ms G++ 2063 B 2014-10-16 09:51:19 哎,为啥1000*100*100的复杂度的dp就不敢敲了呢 ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. HDU-2054 A==B?

    #include<stdio.h>#include<string.h>char n[100000], m[100000];int main(){ int i, j, len_n ...

  2. Java笔记-快速失败and安全失败

    参考资料:http://blog.csdn.net/chenssy/article/details/38151189 快速失败 fail-fast 安全失败 fail-safe java.util包下 ...

  3. some words that I always make mistake

    发音相似容易混淆的词汇 alteration  英 [ɔːltə'reɪʃ(ə)n; 'ɒl-]  美 [,ɔltə'reʃən]  n. 修改,改变:变更 alteration /ˌɔːltəˈre ...

  4. vijosP1499炸毁燃料库

    背景 某天,外星人展开了对地球的侵略,OIer们开始与之周旋... 描述 外星人派出了172849个外星人乘着UFO来到地球,curimit神new带领着OIer们奋力抵抗.curimit神new觉得 ...

  5. 【线段树】HDU 5443 The Water Problem

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 题目大意: T组数据.n个值,m个询问,求区间l到r里的最大值.(n,m<=1000) ...

  6. “/”应用程序中的服务器错误。 / c:\windows\temp目录权限设置

    说明: 1 对该目录的权限是ASP.net生成编译运行的临时文件需要,ASP不需要这个目录是因为ASP的脚本代码是解释执行. 2 Windows2003默认的设置是可以正常运行ASP.net的,造成问 ...

  7. Binary Search Tree Iterator——LeetCode

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...

  8. gtest官方文档浅析

    gtest的所有官方文档:http://code.google.com/p/googletest/w/list 选择单元测试框架的那些事 gtest不是唯一开源的单元测试框架,我也不觉得它是最好的单元 ...

  9. PHP IDE 框架 服务器 相关

    server:nginx  框架:一个比较老的项目用的ZendFramework,最近的新项目用的codeigniter  IDE:  zend studio  Sublime Text https: ...

  10. Flask+Mysql搭建网站之安装Mysql

    安装Mysql # sudo apt-get install mysql-server 安装过程需要输入root密码,这个密码是mysql 的root密码,之后连接mysql会用到,这个要记住. 安装 ...