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的更多相关文章

  1. PAT-1010 Radix

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

  2. 浙江大学PAT考试1009~1012(1010上帝是冠军。。)

    哎,pat1010即使java书面,只有java书面,还增加了两个点,,.啊,智商捉佳,主要pat有些不给明确的范围.造成遐想空间.. 还是按顺序介绍.. 题目地址:http://pat.zju.ed ...

随机推荐

  1. Linux(centos5.0+)unison+inotify-tools触发式双向自动同步

    192.168.1.11是server1, 192.168.1.22是server2. [1]安装inotify-tools   各大linux发行版本都有inotify-tools软件包,建议通过y ...

  2. 二分三角形的时候尤其需要注意!!! HDU 5115 二分+模拟

    题目大意:http://blog.csdn.net/snowy_smile/article/details/49535301 思路:分类讨论,分别在[1,2].(2,3).[3,4).[4,1]相遇, ...

  3. [Java]知乎下巴第0集:让我们一起来做一个知乎爬虫吧哦耶【转】

    文章来源:http://jp.51studyit.com/article/details/16203.htm 作者:  汪海洋 身边的小伙伴们很多都喜欢刷知乎,当然我也不例外, 但是手机刷太消耗流量, ...

  4. Inno Setup入门(二)——修改安装过程中的图片

    修改安装过程中的图片 一般编译之后,安装过程中出现在左边图片是是下图这个样子的: 其实也可以修改它,只需要在setup段中作一点稍微的修改,加一行代码即可: [setup] AppName=Test ...

  5. Learn about images & containers

    Learn about images & containers Docker Engine provides the core Docker technology that enables i ...

  6. zk reconnect

    http://blog.csdn.net/hengyunabc/article/details/41450003 http://blog.csdn.net/hengyunabc/article/det ...

  7. http get with body data

    http://stackoverflow.com/questions/978061/http-get-with-request-body Yes, you can send a request bod ...

  8. 笨方法学python--简介

    该章提到编程新手所需的三种最重要的技术:读和写,注重细节,发现不同. 读 和 写 即熟悉代码中的各种字符. 注 重 细 节 将例子一字不差地打出来,通过实践训练自己 发 现 不 同 这个是通过长年累月 ...

  9. getopt(分析命令行参数)

    ref:http://vopit.blog.51cto.com/2400931/440453   相关函数表头文件         #include<unistd.h>定义函数       ...

  10. listener、context、filter、servlet及其加载顺序

    首先说加载顺序:context-param—>listener —> filter —> servlet 这四类加载顺序与配置顺序无关,对于每一类内部的加载顺序,与配置顺序有关: l ...