1010 Radix
1010 Radix

注意点
- 如
111 1 1 10类似情况下,若n为个位数,如果本身比另一个数小,则多少的进制都是没有用的(可能会造成空循环而超时),不过好像没有这么一个测试用例- 进制应该比最少数据中的最大的数要大一,如8最少是9进制的数,z最少是36进制的数
- 注意算法中的超时问题如
9999999999 11 1 10很容易超时,注意匹配的算法- 如果用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的更多相关文章
- PAT 解题报告 1010. Radix (25)
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
- 1010 Radix (25 分)
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 1 ...
- 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 ...
- PAT甲级1010. Radix
PAT甲级1010. Radix (25) 题意: 给定一对正整数,例如6和110,这个等式6 = 110可以是真的吗?答案是"是",如果6是十进制数,110是二进制数. 现在对于 ...
- pat 甲级 1010. Radix (25)
1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...
- PAT 1010 Radix(X)
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = ...
- PAT甲组 1010 Radix (二分)
1010 Radix (25分) Given a pair of positive integers, for example, \(6\) and \(110\), can this equatio ...
- 已经菜到不行了 PAT 1010. Radix (25)
https://www.patest.cn/contests/pat-a-practise/1010 题目大意: 输入四个数字,a,b,c,d. a和b是两个数字,c=1表示是第一个数字,c=2表示是 ...
- 1010. Radix (25)(未完成)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
随机推荐
- python tkinter模版
import tkinter import time import threading from tkinter import ttk event = threading.Event() once=0 ...
- 转载:TDM协议
转自http://www.wangdali.net/i2s/ 1. PCM简介 PCM (Pulse Code Modulation) 是通过等时间隔(即采样率时钟周期)采样将模拟信号数字化的方法.图 ...
- [CF653F] Paper task - 后缀数组,线段树,vector
[CF653F] Paper task Description 给定一个括号序列,统计合法的本质不同子串的个数. Solution 很容易想到,只要在传统统计本质不同子串的基础上修改一下即可. 考虑经 ...
- Linux_oracle 数据库监听
su - oracle //切换到oracle用户模式下 cd $ORACLE_home/bin //进入oracle安装目录 lsnrctl start //启动监听 lsnrctl status ...
- LitElement(一)概述
1.一些感悟 自从踏入编程领域开始,从html,css,JavaScript,jQuery,bootstrap开始接触前端,经常用NodeJS,ejs等模板语言来写个简单的页面,感觉蛮简单的,也不怎么 ...
- 第一篇,VScode插架以及配置项
由于在开发的时候我们经常因为ESLint规范把自己搞的头晕眼花,修改起来又很浪费时间.所以我特别做个记录,如下代码可以轻松搞的. 工欲善其事必先利器,如果想要在开发的道路上如履平地必须要有得心 ...
- Python中的模块简单认识
将自己定义的方法,变量存放在文件中,为一些脚本或者交互式的解释器实例使用,这个文件称为模块. 细说的话,模块可以分为四个通用类别: 1 使用python编写的.py文件(自定义模块) 2 已被编译为共 ...
- JS高级---逆推继承看原型
逆推继承看原型 function F1(age) { this.age = age; } function F2(age) { this.age = age; } F2.prototype = new ...
- 16day 重定向符号:
>/1> 标准输出重定向符号 2> 错误输出重定向符号 >>/1> 标准输出追加重定向符号 2>> 错误输出追加重定向符号 如何将正确信息和错误信息都输 ...
- 后端——框架——日志框架——logback——《官网》阅读笔记——第一章节
第一章节搭建了logback日志框架的环境,演示了Hello World的示例,并详细分析了示例. 搭建日志框架的过程非常简单,只需要在项目的classpath上添加以下三个jar包,logback- ...