1010 Radix (25 分)
 

Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.

Now for any pair of positive integers N​1​​ and N​2​​, 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:


N1 N2 tag radix

Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set { 0-9, a-z } where 0-9 represent the decimal numbers 0-9, and a-z represent the decimal numbers 10-35. The last number radix is the radix of N1 if tag is 1, or of N2 if tag is 2.

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.

Sample Input 1:

6 110 1 10

Sample Output 1:

2

Sample Input 2:

1 ab 1 2

Sample Output 2:

Impossible
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 500 vector<char> vec; map<char,int> mp; ll tansss(string s,int x){
ll sum = ;
ll t = ;
for(int i=s.size()-;i>=;i--){
sum += mp[s[i]]*t;
t *= x;
}
return sum;
} int main(){
for(int i=;i <= ;i++){
vec.push_back(char(''+i));
}
for(int i=;i <= ;i++){
char temp = char('a'+(i-));
vec.push_back(temp);
} for(int i=;i < vec.size();i++){
mp[vec[i]] = i;
} // while(1){
// string s; cin >> s;
// int radix; cin >> radix;
// cout << tansss(s,radix);
// } string s1,s2;
int tag,radix;
cin >> s1 >> s2 >> tag >> radix; if(tag == ){
ll ok = tansss(s1,radix);
for(int i=;i<=;i++){
if(tansss(s2,i)==ok){
cout << i;
return ;
}
}
cout << "Impossible";
}
else{
ll ok = tansss(s2,radix);
for(int i=;i<=;i++){
if(tansss(s1,i)==ok){
cout << i;
return ;
}
}
cout << "Impossible";
} return ;
}

还要判断溢出。。。打扰了拿16分溜了

 

PAT 1010 Radix(X)的更多相关文章

  1. PAT甲组 1010 Radix (二分)

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

  2. 1010 Radix (25 分)

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

  3. PAT 1085 PAT单位排行(25)(映射、集合训练)

    1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤10​5​​),即考生人数.随 ...

  4. 7-07. PAT排名汇总(25) (结构体 ZJU_PAT)

    题目链接:http://www.patest.cn/contests/ds/7-07 编程能力測试(Programming Ability Test,简称PAT)是浙江大学计算机科学与技术学院主办的专 ...

  5. PAT 1071 小赌怡情(15)(代码)

    1071 小赌怡情(15 分) 常言道"小赌怡情".这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算 ...

  6. PAT 1058 选择题(20)(代码+思路)

    1058 选择题(20 分) 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多. 输入格式: 输入在第一行给出两个正整数 N(≤ 1000)和 M(≤ 100 ...

  7. PAT A1010 Radix (25 分)——进制转换,二分法

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  8. PAT 1010 Radix (二分)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  9. PAT 1010 Radix (25分) radix取值无限制,二分法提高效率

    题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...

随机推荐

  1. [CSP-S模拟测试]:简单的填数(贪心+模拟)

    题目描述 对于一个长度为$n$,且下标从$1$开始编号的序列$a$,我们定义它是「合法的」,当且仅当它满足以下条件:·$a_1=1$·对于$i\in [1,n),a_i\leqslant a_{i+1 ...

  2. 团队冲刺DAY4

    DES算法 算法概要 在DES.java当中创立两个方法分别用作加密和解密 通过 `public static byte[] encrypt(byte[] data, String sKey) 创建方 ...

  3. windows10下Mysql5.7安装指南

    背景 值此国庆70周年之际,为了发扬广大国内软件开发行业,我决定使用MySQL5.7. 呸!实际情况是公司的项目用的是Mysql5.7,但是正式服务器在国外,而且测试服务器也是在国外,关键问题是我这个 ...

  4. 大数据学习笔记之Linux基础(一):Linux初窥

    文章目录 一.Linux入门概述 1.1 概述 1.2 下载地址 1.3 Linux特点 1.4 Linux和Windows区别 二.VM安装相关 2.1 安装VMWare虚拟机 2.2 安装Cent ...

  5. textarea高度随文本内容变化,且不出现滚动条

    通常文本域的写法如下 <textarea type="text" class="form-control pull-left" id="desc ...

  6. camunda流程实例启动的一些简单操作

    public class ZccRuntimeService { RuntimeService runtimeService; RepositoryService repositoryService; ...

  7. java.lang

    package cn.sxt;   import java.lang.*;   public class BooleanDemo {      public static void main(Stri ...

  8. 利用URL Protocol实现网页调用本地应用程序

    http://blog.csdn.net/zssureqh/article/details/25828683

  9. java 重新学习 (六)

    一.java7以后,使用带泛型的接口,类定义变量,那么调用构造器创建对象时构造器的后面不必带上泛型.List<String> list = new ArrayList()<>; ...

  10. 2059-authentication plugin 'caching_sha2_password"cnnot bt loaded :mysql8.0数据库连接不上(Navicat)

    原因:8.0改变了 身份验证插件 , 打开 my.ini (或者my.cofg) 可以看到变更了 5.7及其以前的方式:mysql_native_password 办法: 1:命令行键入数据库: my ...