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 N1 and 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:
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
题意:如果tag=1,则N1是radix进制数,若tag=2,则N2是radix数,问是否存在某进制数使得N2(N1)为N1(N2)的进制数。
分析:因为进制数越大所得到的值越大,比如110,若是二进制,值为6,若为10进制,值为110。
依据这点二分:
1、首先看N1、N2谁大,若N2大交换下N1、N2顺序。2、二分下界为所出现数字中最大数字+1,上界为所给的radix,夹出对应进制数
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-26-14.28.46
* Description : A1010
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
long long convert(string a,long long radix){ //转化为十进制
;
,len=a.size();
;i<len;i++){
temp=isdigit(a[i])? a[i]-;
sum=sum*radix+temp;
}
return sum;
}
long long find_radix(string a,long long num){
//二分法,进制数越大数值越大。先确定上下界:下界是最大值+1,比如987,最起码是一个10进制数。而上界是max(下界,N1的十进制)+1;
char it=*max_element(a.begin(),a.begin());
)+;
long long high=max(low,num);
while(low<=high){
;
long long t=convert(a,mid);
||t>num) high=mid-;
else if(t==num) return mid;
;
}
;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
string N1,N2;
int tag;
long long radix,ans;
cin>>N1>>N2>>tag>>radix;
){
swap(N1,N2);
}
ans=find_radix(N2,convert(N1,radix));
) {
printf("%lld",ans);
}else{
printf("Impossible");
}
;
}
1010 Radix (25 分)的更多相关文章
- 1010 Radix (25 分),PTA
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805507225665536 题意:给定n1.n2两个数,求可以是两 ...
- 1010 Radix (25 分)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- PAT Advanced 1010 Radix(25) [⼆分法]
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
- PAT 1010 Radix (25分) radix取值无限制,二分法提高效率
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
- 1010 Radix (25分)
改了一天也没明白,第7个数据是怎么卡的 #include <bits/stdc++.h> using namespace std; const int maxn=1005; typedef ...
- 【PAT甲级】1010 Radix (25 分)(二分)
题意: 输入两个数可能包含小写字母,1或者2,进制大小.第三个数为代表第一个数是第四个数进制的,求第二个数等于第一个数时进制的大小,不可能则输出Impossible,第三个数为2代表第二个数是第四个数 ...
- PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)
1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...
- PAT 解题报告 1010. Radix (25)
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
- pat 甲级 1010. Radix (25)
1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...
- 1010. Radix (25)(未完成)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
随机推荐
- 去除字符串中的emoji字符
对于使用utf8编码的mysql数据库来说,如果字符串中存在emoji小图像,是不能存进数据库中的,查了一下,原因大概是因为utf8编码可以存1-3个字节的字符,但是emoji是4个字节:解决方法可以 ...
- L236
The Norwegian Authority for Investigation of Economic and Environmental Crime (Okokrim) said the mov ...
- 2019.1.3 WLAN 802.11 a/b/g PHY Specification and EDVT Measurement II - Transmit Spectrum Mask & Current Consumption
Transmit Spectrum Mask Specification – 802.11b SpecificationFor 802.11b 18.4.7.3The transmitted spec ...
- the usage of String
经典算法:(整理汇总) 1)如何快速倒叙: public static char[] reverseArray(char[] c){ char t; for(int i=0;i<c.length ...
- Redis学习第二课:Redis String类型及操作
Strings类型 String是最简单的类型,一个Key对应一个Value,String类型是二进制安全的,可以包含任何数据,比如jpg图片或序列化的对象. Strings类型的操作: Set:设置 ...
- Magento邮件发送完美设置
Magento新站上线伊始,不料在邮件上遇到了问题.此时常用的邮件模板已经编辑完毕,诸如New Account, New Order, Password Forget等. CentOS下发送邮件很简单 ...
- OpenCV 图像旋转实现
1 旋转矩形 首先建议阅读图像旋转算法原理-旋转矩阵,这篇博客可以让你很好地理解图像中的每一个点是如何进行旋转操作的.其中涉及到了图像原点与笛卡尔坐标原点之间的相互转换以及点旋转的一些公式推导. 这里 ...
- 原生js实现数据的双向绑定
原生js实现数据的双向绑定 需要了解的属性是原色js的Object.definePrototype(obj,pop,descript); obj:被构造的对象 pop:被构造的对象的属性,创建对象或修 ...
- XINU安装程序.exe一键配置好XINU实验环境 - imsoft.cnblogs
还在一步一步配置复杂的XINU吗?XINU安装程序.exe一键配置好XINU实验环境. XINU安装程序.exe使用说明: 本程序配合<网络协议分析与实现>/(胡维华等编著)课本使用 ...
- Gym 101630(NEERC 17) D.Designing the Toy
题目大意:给出三视图方向上分别能看到的正方形数a,b,c(1<=a,b,c<=100),在-100<=x,y,z<=100的范围内构造出满足情况的一种正方体的摆放方式 做法很简 ...