题意:

输入两个数可能包含小写字母,1或者2,进制大小。第三个数为代表第一个数是第四个数进制的,求第二个数等于第一个数时进制的大小,不可能则输出Impossible,第三个数为2代表第二个数是第四个数进制的,求第一个数等于第二个数时进制的大小,不可能则输出Impossible。数字的位数最多是十位。

trick:

进制可能很大,所以运算过程中可能会爆long long,不必担心,当成负数处理即可。

AAAAAccepted code:

 #include<bits/stdc++.h>
using namespace std;
string s1,s2;
long long t,rad;
int main(){
cin>>s1>>s2>>t>>rad;
if(t==)
swap(s1,s2);
long long num1=,num2=;
int len1=s1.size(),len2=s2.size();
for(int i=;i<len1;++i){
num1*=rad;
if(s1[i]>=''&&s1[i]<='')
num1+=s1[i]-'';
else
num1+=s1[i]-'a'+;
}
int mx=;
for(int i=;i<len2;++i)
if(s2[i]>=''&&s2[i]<='')
mx=max(mx,s2[i]-'');
else
mx=max(mx,s2[i]-'a'+);
long long l=mx+;
long long r=max(l,num1);
long long mid=;
while(l<=r){
mid=(l+r)>>;
string x=s2;
long long tmp=;
for(int i=;i<len2;++i){
tmp*=mid;
if(x[i]>=''&&x[i]<='')
tmp+=x[i]-'';
else
tmp+=x[i]-'a'+;
}
if(tmp>num1||tmp<)//顺序写反会错
r=mid-;
else if(tmp<num1)//顺序写反会错,因为溢出的话tmp小于0,一定小于num1
l=mid+;
else{
cout<<mid;
return ;
}
}
cout<<"Impossible";
return ;
}

【PAT甲级】1010 Radix (25 分)(二分)的更多相关文章

  1. 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 ...

  2. pat 甲级 1010. Radix (25)

    1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...

  3. PAT Advanced 1010 Radix(25) [⼆分法]

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

  4. PAT甲级1010. Radix

    PAT甲级1010. Radix (25) 题意: 给定一对正整数,例如6和110,这个等式6 = 110可以是真的吗?答案是"是",如果6是十进制数,110是二进制数. 现在对于 ...

  5. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  6. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  7. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  8. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  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. 深入delphi编程理解之消息(四)使用TWMSysCommand结构体的WM_SysCommand消息应用

    通过以下实例拦截窗体WM_SysCommand消息,我们可以获取到很多有趣的数据. 一.程序界面 二.程序代码 unit Unit1; interface uses Windows, Messages ...

  2. 手码两万余字,SpringMVC 包教包会

    1. SpringMVC 简介 1.1 Spring Web MVC是什么 Spring Web MVC 是一种基于 Java 的实现了 Web MVC 设计模式的请求驱动类型的轻量级 Web 框架, ...

  3. warmup

    先简单了解下源码中的2个函数: <?php echo mb_strpos("朋友比生命还重要?或许是吧" . '?',"?"); echo "\ ...

  4. Android如何运行他人工程

    首先新建一个本地的新工程做对比,用记事本打开以下的几个工程文件,把本地工程文件的内容覆盖掉他人工程的文件内容,注意只覆盖两个工程共有的内容条目即可,不要删掉他人工程的其他依赖!(具体哪几个文件本人还没 ...

  5. PL2303HXA自2012已停产

    解决"PL2303HXA自2012已停产,请联系供货商" USB不识别的问题: 问题是WIN10自带的驱动不兼容引起的,只能安装早期驱动,再驱动程序中选择旧版本驱动即可

  6. VMware升级到15版本虚拟机黑屏的解决方法

    1.启动VMware15虚拟机,在菜单栏找到:虚拟机→管理→更改硬件兼容性 2.打开该项,弹出更改硬件兼容性向导对话框,点  下一步,接下来把硬件兼容性改为Workstation 12.x 3.根据提 ...

  7. c++开源库rapidxm

    1.引入头文件: 一般用到的头文件: #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_utils ...

  8. 【MYSQL建库和建表】MYSQL建库和建表

    1.Navicat创建Mysql数据库 2.创建创建用户表和索引 CREATE TABLE `t_user` ( `id` ) NOT NULL AUTO_INCREMENT COMMENT '主键' ...

  9. oracle用户表字段注释

    SELECT C.TABLE_NAME,NUM_ROWS,(select COMMENTS from user_tab_comments WHERE TABLE_NAME=C.TABLE_NAME) ...

  10. VUE项目开发中使用WebSocket

    初始化WebSocket initWebSocket(){ //初始化weosocket const wsuri = 'ws://10.100.45.8:8888/websocket';//ws地址 ...