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 ...
随机推荐
- 洛谷P1147 连续自然数和
https://www.luogu.org/problem/P1147 #include<bits/stdc++.h> using namespace std; int main(){ i ...
- 简述python(threading)多线程
一.概述 import threading 调用 t1 = threading.Thread(target=function , args=(,)) Thread类的实例方法 # join():在子线 ...
- 【metasploit教程】之建立数据库
在我们通过search命令搜索时,我们会发现搜索的很慢(慢搜索)而且会报错: 启动postgresql: service postgresql strart 启动metasploit会开始建立数据表: ...
- Unity中常用的数据结构总结
本篇博文对U3D经常用到的数据结构和各种数据结构的应用场景总结下. 1.几种常见的数据结构 这里主要总结下在工作中常碰到的几种数据结构:Array,ArrayList,List<T>,Li ...
- 如何着手学习WebRTC开发(转)
文章链接:http://www.sohu.com/a/146536246_458408 WebRTC中文社区-国内镜像:https://webrtc.org.cn/mirror/#windows%E2 ...
- asp.net 的 web form 过时了吗
本文链接:https://blog.csdn.net/closurer/article/details/79526006web form 其实是一个超前的设计. 每个厂商都希望服务器端和客户端采用同样 ...
- pip知识点
pip第三方模块保存在\Lib\site-packages目录 安装第三方模块:\Script目录下->shift+鼠标右点打开powershift窗口 ->pip install 模块名 ...
- [lua]紫猫lua教程-命令宝典-L1-01-12. 临时补充2
1.lua的环境变量和函数 (1)_G表 (个人习惯遍历下_G 看看当前环境支持什么库 很多库不是默认就支持的 需要按照流程导入或者加载) 一个全局变量(非函数),内部储存有当前所有的全局函数和全局 ...
- Bugku - 好多压缩包 - Writeup
bugku - 好多压缩包 - Writeup M4x原创,转载请注明出处 这道题前前后后做了好几天,这里记录一下 题目 文件下载 分析 解压下载后的文件,发现有68个压缩文件,并且每个压缩文件里都有 ...
- docker里面安装sqlserver2017
首先要注意,docker一般不做数据持久化容器.如果非要安装可以参考微软官方教程: https://docs.microsoft.com/zh-cn/sql/linux/quickstart-inst ...