时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 青铜 Bronze
题目描述 Description
  1. 回文数是指从左向右念和从右像做念都一样的数。如12321就是一个典型的回文数。
  1. 给定一个进制B(2<=B<=20十进制),输出所有的大于等于1小于等于300且它的平方用B进制表示时是回文数的数。用’A’,’B’……表示1011等等。
输入描述 Input Description

共一行,一个单独的整数B(B用十进制表示)。

输出描述 Output Description

每行两个数字,第二个数是第一个数的平方,且第二个数是回文数。

样例输入 Sample Input
  1. 10
样例输出 Sample Output
  1. 1 1
  1. 2 4
  1. 3 9
  1. 11 121
  1. 22 484
  1. 26 676
  1. 101 10201
  1. 111 12321
  1. 121 14641
  1. 202 40804
  1. 212 44944
  1. 264 69696
数据范围及提示 Data Size & Hint

一道舒心模拟题 点击传送

  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <string>
  5. using namespace std;
  6.  
  7. string a,b,c;
  8. int B,i,j;
  9. int pd(int k)
  10. {
  11. a.clear();
  12. while(k)
  13. {
  14. a+=k%B;
  15. k/=B;
  16. }
  17. int l=,r=a.length()-;
  18. while(l<r)
  19. {
  20. if(a[l++]!=a[r--])
  21. return ;
  22. }
  23. return ;
  24. }
  25. void get(int q)
  26. {
  27. b.clear();
  28. while(q)
  29. {
  30. int d=q%B;
  31. if(d>=)
  32. b+=char(d+);
  33. else b+=d;
  34. q/=B;
  35. }
  36. }
  37. void geta(int w)
  38. {
  39. c.clear();
  40. while(w)
  41. {
  42. int e=w%B;
  43. if(e>=)
  44. c+=char(e+);
  45. else c+=e;
  46. w/=B;
  47. }
  48. }
  49. int main()
  50. {
  51. scanf("%d",&B);
  52. for(i=;i<=;++i)
  53. {
  54. if(pd(i*i))
  55. {
  56. get(i);
  57. geta(i*i);
  58. for(j=b.length()-;j>=;--j)
  59. if(b[j]>='A'&&b[j]<='Z') cout<<b[j];
  60. else cout<<int(b[j]);
  61. cout<<" ";
  62. for(j=c.length()-;j>=;--j)
  63. if(c[j]>='A'&&c[j]<='Z') cout<<c[j];
  64. else cout<<int(c[j]);
  65. cout<<endl;
  66. }
  67. }
  68. return ;
  69. }

codevs 1390 回文平方数 USACO的更多相关文章

  1. 洛谷P1206 [USACO1.2]回文平方数 Palindromic Squares

    P1206 [USACO1.2]回文平方数 Palindromic Squares 271通过 501提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有 ...

  2. 洛谷 P1206 [USACO1.2]回文平方数 Palindromic Squares

    P1206 [USACO1.2]回文平方数 Palindromic Squares 题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2< ...

  3. Palindromic Squares 回文平方数

    1.2.4 Palindromic Squares 回文平方数 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 139  Solved: 66[Submit ...

  4. 【USACO 1.2.4】回文平方数

    [题目描述] 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下 ...

  5. USACO Training Section 1.2 [USACO1.2]回文平方数

    题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且 ...

  6. HDU 4632 Palindrome subsequence(区间DP求回文子序列数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题目大意:给你若干个字符串,回答每个字符串有多少个回文子序列(可以不连续的子串).解题思路: 设 ...

  7. LOJ 2452 对称 Antisymmetry——用hash求回文串数

    概念 用hash求最长回文串/回文串数 首先,易知,回文串具有单调性. 如果字符串 $s[l...r]$ 为回文串串,那么 $s[x...y]$($l < x, y < r$ 且 $|l- ...

  8. HDU5658:CA Loves Palindromic (回文树,求区间本质不同的回文串数)

    CA loves strings, especially loves the palindrome strings. One day he gets a string, he wants to kno ...

  9. SPOJ STC02 - Antisymmetry(Manacher算法求回文串数)

    http://www.spoj.com/problems/STC02/en/ 题意:给出一个长度为n的字符串,问其中有多少个子串s可以使得s = s按位取反+翻转. 例如样例:11001011. 10 ...

随机推荐

  1. 2.11 Hive中数据导入导出Import和Export使用

    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport 一.Export.Import Export ...

  2. 清理win10系统c盘

    本人C盘是128G SSD硬盘,Win10系统盘和一些常用的程序都装在这个盘(特大程序除外),目的是为了使用这些程序时提高响应速度.但是本人电脑使用1年,突然发现C盘以占用近70G的空间,实在是吓蒙撒 ...

  3. Numpy学习笔记<1>

    1 numpy的ndarray:一种多维数组 a:创建ndarry   注意:np.array会尝试为新建的数组一个合适的数据类型 保存在dtype中 b:嵌套序列转换为一个多维数组 c:输出数据类型 ...

  4. E20190404-hm

    prepend vt. 预先考虑,预先计划,预谋;

  5. 无法打开包括文件:“SDKDDKVer.h”: No such file or directory

    在已经装有Visual Studio 2010的系统中,同时安装Visual Studio 2012,安装过程很顺利,但到使用VS2013时,却出问题了. 本文主要介绍:VS中新建工程编译时出现,“无 ...

  6. Unity3D中常用的数据结构总结与分

    阅读目录 1.几种常见的数据结构 2.几种常见数据结构的使用情景 来到周末,小匹夫终于有精力和时间来更新下博客了.前段时间小匹夫读过一份代码,对其中各种数据结构灵活的使用赞不绝口,同时也大大激发了小匹 ...

  7. 如何实现一个无边框Form的移动和改变大小(一)

    很多时候我们不希望使用Windows提供的窗体. 我们希望使用一个无边框的窗体,什么border,caption透明就行了. 下面我们来说下一些实现方法. 这个方法要求窗体自定义的border siz ...

  8. Aandroid 解决apk打包过程中出现的“Certificate for <jcenter.bintray.com> doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的问题

    有时候,apk打包过程中会出现“Certificate for <jcenter.bintray.com> doesn't match any of the subject alterna ...

  9. pytest入门学习(1)

    系统ubuntu 12.04 , 可上网 一.安装: 1.安装 setuptools 下载页面:https://bitbucket.org/pypa/setuptools/get/default.ta ...

  10. C++中各种简写及全称的库

    ATL(Active TEmplate Library)活动模板库 RPC(Remote Procedure Call Protocol)远程过程调用协议 DCE(Distributed Comput ...