1010 Radix

注意点

  1. 111 1 1 10类似情况下,若n为个位数,如果本身比另一个数小,则多少的进制都是没有用的(可能会造成空循环而超时),不过好像没有这么一个测试用例
  2. 进制应该比最少数据中的最大的数要大一,如8最少是9进制的数,z最少是36进制的数
  3. 注意算法中的超时问题如9999999999 11 1 10很容易超时,注意匹配的算法
  4. 如果用c等强类型语言写,注意溢出问题,int类型肯定是不够的

python3代码

def getNum(num, radix):
sum = 0
count = 0
for i in num[::-1]:
if i <= '9':
sum += int(i)*pow(radix, count)
else:
sum += (ord(i)-87)*pow(radix, count)
count += 1
return sum num0 = 0
num1 = 0
data_list = input().split(" ") if data_list[2] == '1':
num0 = getNum(data_list[0], int(data_list[3]))
num1 = data_list[1]
else:
num0 = getNum(data_list[1], int(data_list[3]))
num1 = data_list[0] if len(num1) == 1 and getNum(num1, 36) < num0:
print("Impossible")
exit() max_c = max(num1)
if max_c > '9':
max_c = ord(max_c) - 87
else:
max_c = int(max_c) radix = max_c + 1
result = getNum(num1, radix) basic = 5
while result < num0:
radix *= basic
result = getNum(num1, radix)
if result > num0:
radix //= basic
basic = radix // 2
result = getNum(num1, radix)
while result < num0:
if basic == 0:
break
radix += basic
result = getNum(num1, radix)
if result > num0:
radix -= basic
result = getNum(num1, radix)
basic //= 2 if result == num0:
print(radix)
else:
print("Impossible")

1010 Radix的更多相关文章

  1. PAT 解题报告 1010. Radix (25)

    1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...

  2. 1010 Radix (25 分)

    1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 1 ...

  3. PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)

    1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...

  4. PAT甲级1010. Radix

    PAT甲级1010. Radix (25) 题意: 给定一对正整数,例如6和110,这个等式6 = 110可以是真的吗?答案是"是",如果6是十进制数,110是二进制数. 现在对于 ...

  5. pat 甲级 1010. Radix (25)

    1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...

  6. PAT 1010 Radix(X)

    1010 Radix (25 分)   Given a pair of positive integers, for example, 6 and 110, can this equation 6 = ...

  7. PAT甲组 1010 Radix (二分)

    1010 Radix (25分) Given a pair of positive integers, for example, \(6\) and \(110\), can this equatio ...

  8. 已经菜到不行了 PAT 1010. Radix (25)

    https://www.patest.cn/contests/pat-a-practise/1010 题目大意: 输入四个数字,a,b,c,d. a和b是两个数字,c=1表示是第一个数字,c=2表示是 ...

  9. 1010. Radix (25)(未完成)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

随机推荐

  1. 动图演示23个鲜为人知的VSCode快捷键

    动图演示23个鲜为人知的VSCode快捷键 原文地址:dev.to/devmount/23… 代码同步浏览器 安装vccode 安装live server插件 尽管我在VS Code中经常使用许多快捷 ...

  2. 【Python】字符串处理方法

  3. 图像滤波—opencv函数

      函数原型 方框滤波 ,-), bool normalize = true, int borderType = BORDER_DEFAULT) 均值滤波 ,-), int borderType = ...

  4. mysql(1):简介

    typora-root-url: ./ SQL语法顺序和执行顺序 SQL语法顺序 SELECT [DISTINCT] <select_list> FROM <left_table&g ...

  5. Java-POJ1007-DNA Sorting

    题目大意: 你的任务是分类DNA字符串(只有ACGT四个字符,所有字符串长度相同). 根据逆序数,排序程度从好到差. 第一次用到了“类”,和c++里的结构体有类似之处 一次AC,简单暴力的冒泡排序,要 ...

  6. Java的多态-进阶

    Java的多态——进阶 总括 Parent p = new Child(); 反之,Child() c = new Parent(); 会报错. 当使用多态方式调用方法时,首先检查父类中是否有该方法. ...

  7. 浏览器的主要构成High Level Structure

    浏览器的主要组件包括: 1.     用户界面- 包括地址栏.后退/前进按钮.书签目录等,也就是你所看到的除了用来显示你所请求页面的主窗口之外的其他部分 2.     浏览器引擎- 用来查询及操作渲染 ...

  8. window cmd下常用操作

    创建文件夹 mkdir 创建空文件 type nul>文件名 进入目录 cd 进入分区 分区名 引入文件 当前文件: ./文件名 或 直接文件名 上一级目录文件及上一级目录下子文件:../文件名 ...

  9. Linux使用mount挂载samba共享文件夹

    挂载smb的目录,使用读写644权限 mount -t cifs -o "rw,dir_mode=0644,file_mode=0644,username=username,password ...

  10. Verilog 编写规范

    在学习Python时,作者有一句话对我影响很大.作者希望我们在学习编写程序的时候注意一些业内约定的规范.在内行人眼中,你的编写格式,就已经暴露了你的程度.学习verilog也是一样的道理,一段好的ve ...