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. hdu_2608_0 or 1_数论

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2608 反正我是没找出这个规律的,规律参考的别人的! /* 分析:假设数n=2^k*p1^s1*p2^s ...

  2. Mac 下格式化U盘

    diskutil list 查看U盘盘符: lapommedeMacBook-Pro:~ lapomme$ diskutil list /dev/disk0 (internal, physical): ...

  3. flash Ane

    1.ANE简介 Adobe AIR Native Extension,Adobe AIR的本地扩展,简称ANE.什么叫本地扩展?因为Adobe AIR是跨平台的一个运行时,可以在Windows,Mac ...

  4. Linux中nmon的安装与使用【转】

      一.下载nmon. 根据CPU的类型选择下载相应的版本:http://nmon.sourceforge.net/pmwiki.php?n=Site.Downloadwget http://sour ...

  5. 微信支付WxpayAPI_php_v3(一)sdk简介与错误修改

    经过断断续续将近一周的时间终于把微信支付调通了. 这里总结一下,算是给后来者有个指引.少踩坑!!!! 开发语言:php5.5 语言框架:laravel5.2 微信sdk:WxpayAPI_php_v3 ...

  6. 12c meet sysdba meet ORA-01017: invalid username/password; logon denied

    checklist: 1.12c: threaded_execution=true Prevents OS Login As Sysdba 2. The following database para ...

  7. springmvc中的几个问题

    一   url-pattern的问题: <!-- No mapping found for HTTP request with URI [/WEB-INF/jsp/homePage.jsp] i ...

  8. MFC 透明内存DC

    在MFC中绘制比较复杂图形,通常采用双缓冲技术来绘图,的确可以大大加快绘制速度和减少闪烁,但是有些情况也不尽然. 我最近遇到了一个问题,采用的也是双缓冲来加快绘图,但是绘制效果还是不尽人意.A对象里大 ...

  9. php 判断是不是https链接

    如果当前运行的 PHP 版本等于或高于提供的版本号,该函数返回布尔值 TRUE ,反之则返回 FALSE . function is_https() { if (!empty($_SERVER['HT ...

  10. linux系统定时重启tomcat

    #touch auto-start.sh [root@Linux opt]# echo $LANGen_US.UTF-8 #vim auto-start.sh #!/bin/sh export LAN ...