ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
At the ruins of Wat Phra Si Sanphet (วดพระศรสรรเพชญ), one can find famous inscriptions that have only recently been decoded. Several numbers written using Thai numerals decorate these ruins.
A couple of years ago, the famous Peruvian researcher Renzo "el intrépido" Morales found out that most numbers found at the ruins are palindromic, that is, they represent the same number when read backwards. For instance, 171 is palindromic, whereas 17 is not.
Intrigued by the existence of non palidromic numbers as decorations in the ruins, Renzo found out that, while these numbers are not palindromic when represented in base 10 (which is the base used in the Thai numeral system), they are palindromic when represented in another base. For b > 0, the base-b representation of a number N is the sequence amam - 1... a1a0 so that 0 ≤ ai ≤ b - 1 for each 0 ≤ i ≤ m, am ≠ 0, and
ambm + am - 1bm - 1 + ... + a1b + a0 = N.For the previous example, the base-2 representation of 17 is 10001, which is palindromic.
To validate his discovery, Renzo wants you to write a program that takes a number represented in base 10 and checks in which bases from 2 to 16 such number has a palindromic representation.
Input
The first line has a single integer T, the number of test cases.
Each test case has a single line with an integer N written in base 10.
Output
For each test case, print in a single line a space-separated list of integers, from 2 to 16 and in increasing order, of the bases for which the representation of N is palindromic. If N does not have a palindromic representation for any of the bases from 2 to 16, print -1.
Limits
- 0 ≤ T ≤ 103
- 0 ≤ N < 231
Sample Input
2
17
2570
2 4 16
4 16
/*/
题意:
给你一个数,将这个数换成2~16进制的任何数,如果换成其他进制的数之后能够形成一个回文数【不懂去百度】就输出这个进制。 如果一个都不能形成回文数,输出 -1 。 模拟短除法,暴力解题。 AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdio"
#include"string"
#include"vector"
#include"queue"
#include"cmath"
using namespace std;
#define FK(x) cout<<"["<<x<<"]"<<endl
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define bigfor(x) for(int qq=1;qq<=x;qq++)
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout) int ans[20]; bool ok(int n,int i) {
memset(ans,0);
int erear=0;
while(n) {
ans[erear++]=n%i;
n/=i;
}
for(int j=0; j<erear/2; j++) {
if(ans[j]!=ans[erear-1-j])return 0;
}
return 1;
} int main() {
int T;
scanf("%d",&T);
bigfor(T) {
int n;
scanf("%d",&n);
int first=1;
int sign=1;
for(int i=2; i<17; i++) {
if(ok(n,i)) {
if(first) first=0;
else printf(" ");
printf("%d",i);
sign=0;
}
}
if(sign)puts("-1");
else puts("");
}
return 0;
}
ACM: Gym 101047B Renzo and the palindromic decoration - 手速题的更多相关文章
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题)
layout: post title: (寒假开黑gym)2018 ACM-ICPC, Syrian Collegiate Programming Contest(爽题) author: " ...
- ACM: Gym 100935F A Poet Computer - 字典树
Gym 100935F A Poet Computer Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d &am ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
随机推荐
- PYTHON文件操作(二)
class file(object) def close(self): # real signature unknown; restored from __doc__ 关闭文件 "" ...
- Web APP 之rem的使用
移动端web app的开发,之前开发直接使用px像素做单位,这样子做对于传统的PC端开发来说,个人比较习惯,但是对于移动端在来,有说逞强.最明显是切图效果与设计师想达到的效果有些差距,比如<he ...
- CAIN怎么嗅探路由密码
Cain & Abel 是由Oxid.it开发的一个针对Microsoft操作系统的免费口令恢复工具.号称穷人使用的L0phtcrack.它的功能十分强大,可以网络嗅探,网络欺骗,破解加密口令 ...
- matlab更改打开时候默认路径
每次打开matlab都会的修改默认路径,是一件有些烦恼的事情.所以,就想尝试更改默认路径 方法如下: 1.在matlab安装目录,找到toolbox文件夹,打开local文件件,打开matlabrc. ...
- C#接口的作用(经典)
C#接口是一个让很多初学C#者容易迷糊的东西,用起来好像很简单,定义接口,里面包含方法,但没有方法具体实现的代码,然后在继承该接口的类里面要实现接口的所有方法的代码,但没有真正认识到接口的作用的时候就 ...
- Unity3D 原生Android结合UnityPlayerActivity开发遇到的问题
需求是原生Android 的Activity启动UnityPlayerActivity,按Back键后返回原来的Activity 1.在AndroidManifest.xml中的UnityPlayer ...
- go:channel(未完)
注:1)以下的所有讨论建立在包含整形元素的通道类型之上,即 chan int 2)对于“<-”我的理解是,它可能是一个操作符(接收操作符),也 可能是类型的一部分(如“chan<- in ...
- pureftp 服务
没啥图,不喜勿喷---_- ftp(file transfer protocol)--文件传输协议 (a)官网:www.pureftpd.org (b)原理 让用户连接上一个远程计算机(运行FTP ...
- cocoapods真机调试出现问题解决
swift中使用cocoapods时,Podfile中必须写上 use_frameworks! 使用cocoapods导入框架在真机调试出现问题的解决方案: 1.build phases 2.+ ne ...
- sha1散列(C语言)
/** * \file sha1.h * * \brief SHA-1 cryptographic hash function * * Copyright (C) 2006-2010, Brainsp ...