BestCoder13 1001.Beautiful Palindrome Number(hdu 5062) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5062
题目意思:给出 N,找出 1 ~ 10^N 中满足 Beautiful Palindrome Numbers (BPN)的数量有多少。 满足 BPN 的条件有两个:(1)回文串 (2)对称的部分从左到右递增排放。
(1)版本 1 (比较麻烦,建议看版本2) 46ms
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int N = + ;
int ans[N];
int num[N];
int l, ll; bool is_Palindrome(int tmp)
{
l = ;
while (tmp > )
{
num[l++] = tmp % ;
tmp /= ;
}
l--;
for (int i = ; i <= l/; i++)
{
if (num[i] != num[l-i])
return false;
if (num[i] >= num[i+] && i != l/)
return false;
}
return true;
} int main()
{
int cnt;
ans[] = ;
ans[] = ;
//ans[6] = 258;
ll = , cnt = ;
for (int i = ; i <= 1e6; i++)
{
if (is_Palindrome(i))
cnt++;
if (i == )
ans[ll++] = cnt;
if (i == )
ans[ll++] = cnt;
if (i == )
ans[ll++] = cnt;
if (i == )
ans[ll++] = cnt;
if (i == 1e6)
ans[ll] = cnt;
}
int T, n;
while (scanf("%d", &T) != EOF)
{
while (T--)
{
scanf("%d", &n);
printf("%d\n", n == ? : ans[n]);
}
}
return ;
}
(2)版本 2 (主要利用各种字符串处理函数) 250ms
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = + ;
char str1[N], str2[N];
int ans[N]; int main()
{
for (int i = ; i <= 1e6; i++)
{
sprintf(str1, "%d", i);
int len = strlen(str1);
strcpy(str2, str1);
reverse(str2, str2+len);
if (strcmp(str1, str2))
continue;
bool flag = true;
for (int j = ; j < (len+)/; j++)
{
if (str1[j-] >= str2[j])
{
flag = false;
break;
}
}
if (flag)
ans[len]++;
}
for (int i = ; i <= ; i++)
ans[i] += ans[i-]; int t, n;
while (scanf("%d", &t) != EOF)
{
while (t--)
{
scanf("%d", &n);
printf("%d\n", n == ? : ans[n]); // 10^0 也要考虑,即1
}
}
return ; }
听说还可以用组合数学做,一个一个数当然也行
BestCoder13 1001.Beautiful Palindrome Number(hdu 5062) 解题报告的更多相关文章
- BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...
- BestCoder10 1001 Revenge of Fibonacci(hdu 5018) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 题目意思:给出在 new Fibonacci 中最先的两个数 A 和 B(也就是f[1] = A ...
- HDU 5062 Beautiful Palindrome Number(数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5062 Problem Description A positive integer x can re ...
- BestCoder8 1001.Summary(hdu 4989) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 题目意思:给出 n 个数,然后将这些数两两相加,得到 n*(n-1) /2 对和,把重复的和去掉 ...
- BestCoder19 1001.Alexandra and Prime Numbers(hdu 5108) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5108 题目意思:给出一个数正整数 N,N <= 1e9,现在需要找出一个最少的正整数 M,使得 ...
- BestCoder17 1001.Chessboard(hdu 5100) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5100 题目意思:有一个 n * n 的棋盘,需要用 k * 1 的瓷砖去覆盖,问最大覆盖面积是多少. ...
- BestCoder12 1001.So easy(hdu 5058) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5058 (格式有点问题,为了方便阅读---整个复制下来吧) 题目意思:给出两个长度都为 n 的集合你,问 ...
- BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4985 题目意思:有 n 个数,对于第 i 个数给出 σ(i) 的值.求出互不相交的循环的个数,并输出每 ...
- BestCoder3 1001 Task schedule(hdu 4907) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题目意思:给出工作表上的 n 个任务,第 i 个任务需要 ti 这么长的时间(持续时间是ti ~ ...
随机推荐
- 淘宝业务常用english
ADX ad exchange 广告交易平台 coupon 赠品 CPC cost per click CPS cost per sales CT ...
- 5.Android之image控件学习
Android中经常用到图片,比如图片浏览.图标等等,今天学习下image控件,image控件主要有ImageButton和ImageView两种. (1)ImageButton 在布局文件增加: & ...
- Bootstrap教程:[4]栅格系统详解
http://jingyan.baidu.com/article/6f2f55a1852aa1b5b83e6c5a.html 们都知道bootstrap3.0使用了四种栅格选项来形成栅格系统,这四种选 ...
- Spring学习1-初识Spring
一.简介 1.Spring是一个开源的控制反转(Inversion of Control ,IoC)和面向切面(AOP)的容器框架.它的主要目得是简化企业开发. 2.为何要使用Spring? ...
- jquery------提供灵活的方法参数
index.jsp <h1 >再次重逢的世界</h1> my.js $(document).ready(function(){ (function($){ $.fn.shado ...
- ngrok反向代理
关于ngrok ngrok 是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道.ngrok 可捕获和分析所有通道上的流量,便于后期分析和重放. 为什么使用ngrok? ...
- 如何让ThinkPHP的模板引擎达到最佳效率
默认情况下ThinkPHP框架系统默认使用的模板引擎是内置模板引擎.内置模板引擎支持模板文件中采用php原生态代码和模板标签的混合使用.ThinkPHP官方开发文档说,这种默认的内置模板引擎的性能是高 ...
- Antenna Placement(匈牙利算法 ,最少路径覆盖)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6991 Accepted: 3466 ...
- Linux简单的常用命令——纯手打(慢慢积累)
==============linux下快捷键==================ctrl+insert 复制shift +insert 粘贴 输入文件名的前三个字母,按tab键自动补全文件名 在vi ...
- FineUI第六天---表单控件
表单控件 所有表单控件都有的属性有: ShowLabel:是否显示标签(默认值:true). ShowEmptyLabel:是否显示空白的标签(默认值:false). Label:标签文本(默认值:& ...