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 ...
随机推荐
- [CodeIgniter4]故障排除和本地开发服务器
故障排除 以下是一些常见的安装问题,以及建议的解决方法. 我必须在我的URL中包含index.php 如果``/mypage/find/apple``类似的URL``/index.php/mypage ...
- Paper: A novel method for forecasting time series based on fuzzy logic and visibility graph
Problem Forecasting time series. Other methods' drawback: even though existing methods (exponential ...
- AD转换器的主要技术指标
1)分辩率(Resolution) 指数字量变化一个最小量时模拟信号的变化量,定义为满刻度与2n的比值.分辩率又称精度,通常以数字信号的位数来表示. 2) 转换速率(Conversion Ra ...
- linux网卡
手动启动 ifup eth0 查询网卡配置信息 vim /etc/udev/rules.d/70-persistent-net.rules 备注:可以修改网卡名称和MAC地址
- python3 yield实现假的多并发
import time def fun1(): while True: print("fun1") time.sleep(0.1) yield def fun2(): while ...
- 跨站跟踪攻击(CST/XST)
XSS与httponly 正常情况下,客户端脚本(如JS脚本)是可以通过document.cookie函数获得,这样如果有XSS跨站漏洞,cookie很容易被盗取.浏览器有一个安全策略,通过设置coo ...
- 手机大厂必备测试技能-GMS 认证
GMS认证背景 在之前的一篇文章有给各位小伙伴们科普过关于GMS的作用,http://www.lemfix.com/topics/266 "墙"内的小伙伴可能很少会用到这样的服务, ...
- git创建远程分支并推送
1.查看所有分支(-a=>'查看全部的分支') git branch -a 2.创建本地test分支 git branch test 2.2切换test分支 git checkout test ...
- C#常见几种集合比较
1. ArrayList 1.1 ArrayList是一个特殊数组,通过添加和删除元素就可以动态改变数组的长度. ArrayList集合相对于数组的优点:支持自动改变大小,可以灵活的插入元素,可以灵活 ...
- 本地cmd连接远程mysql数据库
一.登录远程mysql 输入mysql -h要远程的IP地址 -u设置的MySQL用户名 -p登录用户密码 例如:mysql -h 192.168.1.139 -u root -p dorlocald ...