codevs 1390 回文平方数 USACO
- 回文数是指从左向右念和从右像做念都一样的数。如12321就是一个典型的回文数。
- 给定一个进制B(2<=B<=20十进制),输出所有的大于等于1小于等于300且它的平方用B进制表示时是回文数的数。用’A’,’B’……表示10,11等等。
共一行,一个单独的整数B(B用十进制表示)。
每行两个数字,第二个数是第一个数的平方,且第二个数是回文数。
- 10
- 1 1
- 2 4
- 3 9
- 11 121
- 22 484
- 26 676
- 101 10201
- 111 12321
- 121 14641
- 202 40804
- 212 44944
- 264 69696
一道舒心模拟题 点击传送
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <string>
- using namespace std;
- string a,b,c;
- int B,i,j;
- int pd(int k)
- {
- a.clear();
- while(k)
- {
- a+=k%B;
- k/=B;
- }
- int l=,r=a.length()-;
- while(l<r)
- {
- if(a[l++]!=a[r--])
- return ;
- }
- return ;
- }
- void get(int q)
- {
- b.clear();
- while(q)
- {
- int d=q%B;
- if(d>=)
- b+=char(d+);
- else b+=d;
- q/=B;
- }
- }
- void geta(int w)
- {
- c.clear();
- while(w)
- {
- int e=w%B;
- if(e>=)
- c+=char(e+);
- else c+=e;
- w/=B;
- }
- }
- int main()
- {
- scanf("%d",&B);
- for(i=;i<=;++i)
- {
- if(pd(i*i))
- {
- get(i);
- geta(i*i);
- for(j=b.length()-;j>=;--j)
- if(b[j]>='A'&&b[j]<='Z') cout<<b[j];
- else cout<<int(b[j]);
- cout<<" ";
- for(j=c.length()-;j>=;--j)
- if(c[j]>='A'&&c[j]<='Z') cout<<c[j];
- else cout<<int(c[j]);
- cout<<endl;
- }
- }
- return ;
- }
codevs 1390 回文平方数 USACO的更多相关文章
- 洛谷P1206 [USACO1.2]回文平方数 Palindromic Squares
P1206 [USACO1.2]回文平方数 Palindromic Squares 271通过 501提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 暂时没有 ...
- 洛谷 P1206 [USACO1.2]回文平方数 Palindromic Squares
P1206 [USACO1.2]回文平方数 Palindromic Squares 题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2< ...
- Palindromic Squares 回文平方数
1.2.4 Palindromic Squares 回文平方数 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 139 Solved: 66[Submit ...
- 【USACO 1.2.4】回文平方数
[题目描述] 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下 ...
- USACO Training Section 1.2 [USACO1.2]回文平方数
题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且 ...
- HDU 4632 Palindrome subsequence(区间DP求回文子序列数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题目大意:给你若干个字符串,回答每个字符串有多少个回文子序列(可以不连续的子串).解题思路: 设 ...
- LOJ 2452 对称 Antisymmetry——用hash求回文串数
概念 用hash求最长回文串/回文串数 首先,易知,回文串具有单调性. 如果字符串 $s[l...r]$ 为回文串串,那么 $s[x...y]$($l < x, y < r$ 且 $|l- ...
- HDU5658:CA Loves Palindromic (回文树,求区间本质不同的回文串数)
CA loves strings, especially loves the palindrome strings. One day he gets a string, he wants to kno ...
- SPOJ STC02 - Antisymmetry(Manacher算法求回文串数)
http://www.spoj.com/problems/STC02/en/ 题意:给出一个长度为n的字符串,问其中有多少个子串s可以使得s = s按位取反+翻转. 例如样例:11001011. 10 ...
随机推荐
- 2.11 Hive中数据导入导出Import和Export使用
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+ImportExport 一.Export.Import Export ...
- 清理win10系统c盘
本人C盘是128G SSD硬盘,Win10系统盘和一些常用的程序都装在这个盘(特大程序除外),目的是为了使用这些程序时提高响应速度.但是本人电脑使用1年,突然发现C盘以占用近70G的空间,实在是吓蒙撒 ...
- Numpy学习笔记<1>
1 numpy的ndarray:一种多维数组 a:创建ndarry 注意:np.array会尝试为新建的数组一个合适的数据类型 保存在dtype中 b:嵌套序列转换为一个多维数组 c:输出数据类型 ...
- E20190404-hm
prepend vt. 预先考虑,预先计划,预谋;
- 无法打开包括文件:“SDKDDKVer.h”: No such file or directory
在已经装有Visual Studio 2010的系统中,同时安装Visual Studio 2012,安装过程很顺利,但到使用VS2013时,却出问题了. 本文主要介绍:VS中新建工程编译时出现,“无 ...
- Unity3D中常用的数据结构总结与分
阅读目录 1.几种常见的数据结构 2.几种常见数据结构的使用情景 来到周末,小匹夫终于有精力和时间来更新下博客了.前段时间小匹夫读过一份代码,对其中各种数据结构灵活的使用赞不绝口,同时也大大激发了小匹 ...
- 如何实现一个无边框Form的移动和改变大小(一)
很多时候我们不希望使用Windows提供的窗体. 我们希望使用一个无边框的窗体,什么border,caption透明就行了. 下面我们来说下一些实现方法. 这个方法要求窗体自定义的border siz ...
- 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 ...
- pytest入门学习(1)
系统ubuntu 12.04 , 可上网 一.安装: 1.安装 setuptools 下载页面:https://bitbucket.org/pypa/setuptools/get/default.ta ...
- C++中各种简写及全称的库
ATL(Active TEmplate Library)活动模板库 RPC(Remote Procedure Call Protocol)远程过程调用协议 DCE(Distributed Comput ...