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. php-fpm.conf详细解析篇

    一:php-fpm.conf详细解析篇: pm = static (静态模式)时只需修改 max_children数值 pm = dynamic (动态模式)时只需修改其它三个数值 pm.max_ch ...

  2. java并发编程笔记(二)——并发工具

    java并发编程笔记(二)--并发工具 工具: Postman:http请求模拟工具 Apache Bench(AB):Apache附带的工具,测试网站性能 JMeter:Apache组织开发的压力测 ...

  3. postgis常用的函数

    常见函数:http://postgis.net/docs/reference.html ST_GeometryType(geometry)    ——    返回几何图形的类型 ST_NDims(ge ...

  4. activiti7配置文件activiti.cfg.xml,日志文件log4j.properties及pom文件

    activiti.cfg.xml:<?xml version="1.0" encoding="UTF-8"?><beans xmlns=&qu ...

  5. 对 HTTP HTTPS的认识

    1.HTTP:超文本传输协议 -以明文的形式传输 -效率更高,但是不安全 2.HTTPS:HTTP+SSL -传输之前数据先加密,之后在揭秘 -效率低,但是安全 3.get请求和post请求的区别 - ...

  6. python调用tushare获取沪深A股票资金流向数据

    接口:moneyflow 描述:获取沪深A股票资金流向数据,分析大单小单成交情况,用于判别资金动向 限量:单次最大提取4000行记录,总量不限制 积分:用户需要至少1500积分才可以调取,基础积分有流 ...

  7. pip安装Scrapy因网络问题出错备选方案

    一 更改pypi默认源 执行 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 执行pip instal ...

  8. SpringBoot开发详解(五)--Controller接收参数以及参数校验

    原文链接:http://blog.csdn.net/qq_31001665 如有侵权,请联系博主删除博客,谢谢 Controller 中注解使用 接受参数的几种传输方式以及几种注解:  在上一篇中,我 ...

  9. 2018APIO 进京赶考

    先见识了一下CTSC的操作...涨了见识... 打铁匠x1 见识了个全英文的ppt,各种讲课其实真的讲的很好,只是逻辑性太强反而让完全不会的同学有些尴尬... linux真的令人窒息...GUIDE用 ...

  10. 回头看看HTML5

    前言:自从学习各种框架各种成熟的控件库,越来越觉得疲惫. 一.用语义元素构造网页 在html5中最常用到的页面结构相关的语义元素如下: 页面结构想相关的语义元素 元素 说明 <article&g ...