PAT1010
Given a pair of positive integers, for example, 6 and 110,
给出一对正整数,例如6和110
can this equation 6 = 110 be true?
6=110这个等式能是对的吗
The answer is "yes", if 6 is a decimal number and 110 is a binary number.
答案是yes,如果6是十进制数,110是二进制数
Now for any pair of positive integers N1 and N2,
现在给出任意的一对正整数N1和N2
your task is to find the radix of one number while that of the other is given.
你的任务是找到一个数的进制和另一个数的
Input Specification:
Each input file contains one test case. Each case occupies a line which contains 4 positive integers:
每个输入文件包含一个测试用例,每个测试用例给出一行包含4个正整数
N1 N2 tag radix
Here N1 and N2 each has no more than 10 digits.
N1和N2每个都不会超过10个数字
A digit is less than its radix and is chosen from the set {0-9, a-z}
一个数字最少有一个进制,所以是在0-9,a-z里面选的
where 0-9 represent the decimal numbers 0-9,
0-9表示十进制的0-9
and a-z represent the decimal numbers 10-35.
a-z表示十进制的10-35
The last number "radix" is the radix of N1 if "tag" is 1, or of N2 if "tag" is 2.
最后一个是基数,如果tag是1,这个基数就是N1的,否则是N2的
Output Specification:
For each test case, print in one line the radix of the other number so that the equation N1 = N2 is true.
对于每个测试用例,打印出一行一个基数使得另一个数能满足等式两边相等
If the equation is impossible, print "Impossible". If the solution is not unique, output the smallest possible radix.
如果有等式是不可能成立的,打印出impossible,如果解决方案不唯一,打印出最小的可能的值。
Sample Input 1:
6 110 1 10
Sample Output 1:
2
Sample Input 2:
1 ab 1 2
Sample Output 2:
Impossible
这道题目就是给出两个数,给出一个数的进制,求另一个数的进制,要满足两个数相等的条件下。
给出思路,首先把知道进制的数转换成10进制,然后把另一个不知道进制的数,用二分的思想去找到一个进制,转换成10进制之后能满足两数相等的条件。
做这道题的我已经放弃了,靠,题目给出的是0-9a-z但是最高的进制数并不是36,所以一直错一直错。
给出的思路就这样吧,有了二分的思想我觉得就可以了。
PAT1010的更多相关文章
- PAT-1010 Radix
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 1 ...
- 浙江大学PAT考试1009~1012(1010上帝是冠军。。)
哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...
随机推荐
- time_t
所在的头文件为 time.h 定义为: #ifndef __TIME_T #define __TIME_T /* 避免重复定义 time_t */ typedef long time_ ...
- OpenCV——mixChannels函数
mixChannels Copies specified channels from input arrays to the specified channels of output arrays. ...
- android网络编程之HttpUrlConnection的讲解--实现文件的断点上传
1.网络开发不要忘记在配置文件中添加访问网络的权限 <uses-permission android:name="android.permission.INTERNET"/& ...
- ueditor浏览器 无法上传文件.问题
dll也都引用了 路径绝对tmd没问题 最后 我一点一点的调试发现了问题 草tmd百度程序员 */UE.ajax = function() { //创建一个ajaxRequest对象 var fnSt ...
- asp.net无法触发asp控件的后台方法
前台代码: <asp:Button ID="btnFinish" runat="server" Text="完成" Font-Size ...
- XTEA加密算法
XTEA加密算法 #include <stdint.h> /* take 64 bits of data in v[0] and v[1] and 128 bits of key[0] - ...
- VS2010中安装AjaxControlToolkit
原文地址:http://www.asp.net/ajaxlibrary/act.ashx 第一步 下载Ajax Control Toolkit 进入网址http://ajaxcontroltoolki ...
- 8.1 sikuli报错: 提示没有对应的javaw
对于sikuli,需要安装32位的jdk且不能高于1.7的版本. 对于64位系统的C盘,Program Files文件夹是64位的,Program File(x86)文件夹是32位的 需要安装一个32 ...
- 使用POI生成Excel文件,可以自动调整excel列宽
//autoSizeColumn()方法自动调整excel列宽 importjava.io.FileOutputStream; importorg.apache.poi.hssf.usermodel. ...
- bash和sh区别
在一般的linux系统当中(如redhat),使用sh调用执行脚本相当于打开了bash的POSIX标准模式(等效于bash的 --posix 参数),一般的,sh是bash的“子集”,不是子集的部分. ...