BestCoder Round #13 Beautiful Palindrome Number解题报告
来源:互联网 发布:青岛海尔人工智能 编辑:程序博客网 时间:2024/05/22 08:05
Beautiful Palindrome Number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 404 Accepted Submission(s): 257
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 satisfies0<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 and10N .
Now, we want to know how many Beautiful Palindrome Numbers are between 1 and
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 integerN(0≤N≤6) .
Then T lines follow, each line represent an integer
Output
For each test case, output the number of Beautiful Palindrome Number.
Sample Input
216
Sample Output
9258
题意:
将一个整数用一个序列表示(序列上的值就是该位上的数字),如果序列满足给的条件,就算一个XX数,算有多少个数,可以先暴力,再打表!
将一个整数用一个序列表示(序列上的值就是该位上的数字),如果序列满足给的条件,就算一个XX数,算有多少个数,可以先暴力,再打表!
/*其实思路很简单,但是<span style="font-family:MathJax_Math;">写这个代码的时候,别人总烦着我,弄得心情超不爽,静不下来好好写,弄得被几种特殊情况搞混乱了</span>*/#include<cstdio>#include<math.h>#include<iostream>using namespace std;int an[8];int get(int num) //这个函数可移植还是很高的,它专门用来<span style="font-family:MathJax_Math;">将一个整数分解成一个序列(不过记得这个实现的是倒序表示的,当然在这里无所谓)</span>{int cnt=0;while(num>0){an[cnt++]=num%10;num/=10;}return cnt;}bool check(int cnt) //这里,<span style="font-family:MathJax_Math;">分了两步来讨论,其实主要是一个关注a[i]>a[i+1]另一个是回文数的条件,这两个一起考虑,自己容易乱,这样分开两个步骤来写,</span>{ <span style="font-family:MathJax_Math;"> 其实时间复杂度并没有因为多了个循环而增大(这个我以前一直以为会增大),反而编码的难度小了,自己好写代码!</span>int k=cnt%2==0? (cnt/2)-1:(cnt/2);if(cnt>=3){for(int i=k;i>=1;i--) //<span style="font-family:MathJax_Math;">关注a[i]>a[i+1]</span>{if(an[i]<=an[i-1]){return false;}}}for(int i=0;i<cnt/2;i++) <span style="font-family:MathJax_Math;">//关注回文数条件</span>{if(an[i]!=an[cnt-1-i])return false;}return true;}int main(){int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);int ans=0;for(int i=1;i<=pow(10,n);i++){if(check(get(i)))ans++;}printf("%d\n",ans);}}
0 0
- BestCoder Round #13 Beautiful Palindrome Number解题报告
- HDU 5062 Beautiful Palindrome Number——BestCoder Round #13
- 【BestCoder】HDOJ 5062 Beautiful Palindrome Number
- BestCoder Round#31 1002 beautiful number
- BestCoder Round #55 解题报告
- 【解题报告】BestCoder Round #75
- 【解题报告】BestCoder Round #80
- Bestcoder round#31 解题报告
- Bestcoder round#32 解题报告
- Bestcoder round#33 解题报告
- Bestcoder round#34 解题报告
- Bestcoder round#85 解题报告
- Bestcoder round#84 解题报告
- bestcoder round#86解题报告
- BestCoder Round #1 解题报告
- BestCoder Round #2 解题报告
- HDU-#5062 Beautiful Palindrome Number(Bestcodeer Round #13)
- hdu 5062 Beautiful Palindrome Number(Bestcodeer Round #13)
- GMM, Gaussian Mixture Model, 高斯混合模型
- Thinking for String to Integer (atoi)
- Odoo(OpenERP)补货规则笔记整理 - 草稿
- Linux下c程序的编译方法:
- JSP详细篇——out
- BestCoder Round #13 Beautiful Palindrome Number解题报告
- 创业周之行——公开课《商业模式的创新》
- 【学习】哈夫曼树——哈夫曼编码
- 高内聚低耦合的理解
- 10 Example of Hashtable in Java – Java Hashtable Tutorial
- Linux for sougou ping yin (http://pinyin.sogou.com/linux/help.php)
- MFC框架类、文档类、视图类相互访问的方法
- Linux 系统内核空间与用户空间通信的实现与分析
- 文章索引