题意:

输入两个数可能包含小写字母,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. 世界坐标转到UGUI坐标

    public static Vector3 WorldToUI(Camera camera,Vector3 pos){ CanvasScaler scaler = GameObject.Find(&q ...

  2. 清华大学慕课 (mooc) 数据结构-邓俊辉-讲义-合并版

    邓公的数据结构一直好评如潮,可惜我如今才开始学习它.QAQ 昨天,<数据结构 (2020 春)>的讲义已经推到清华大学云盘上了.苦于 10 拼页的打印版不易在 PC 上阅读(手机上更是如此 ...

  3. GO学习之 安装Go语言及搭建Go语言开发环境

    一.下载 1.下载地址 Go官网下载地址:https://golang.org/dl/ Go官方镜像站(推荐):https://golang.google.cn/dl/ 2.版本的选择 Windows ...

  4. 02-Spring的IOC示例程序(通过id获取对象)

    *******通过IOC容器创建id对象并为属性赋值******** 整体结构: ①创建一个java工程 ②导包 ③创建log4j.properties日记配置文件 # Global logging ...

  5. Comparable

    为什么会有Comparable与Comparator接口? 引入策略模式   目录 引入 Comparable接口的来龙去脉 引入Comparator接口 什么是策略模式? 使用了策略模式有什么好处? ...

  6. 12、API - 输入设备(API - Input Devices)

    学习目录:树莓派学习之路-GPIO Zero 官网地址:https://gpiozero.readthedocs.io/en/stable/api_input.html 环境:UbuntuMeta-1 ...

  7. 吴裕雄 PYTHON 人工智能——智能医疗系统后台智能分诊模块及系统健康养生公告简约版代码展示

    #coding:utf-8 import sys import cx_Oracle import numpy as np import pandas as pd import tensorflow a ...

  8. yii2.0 验证码

    首先我们在控制器里创建一个actions方法,用于使用yii\captcha\CaptchaAction <?php namespace app\controllers; use YII; us ...

  9. 3 爬虫cookie的处理办法

    cookie的应用和处理 - cookie:服务器端记录客户端的相关状态 - 处理cookie的方式: - 手动处理:不建议 页面找隐藏的标签,获取value - 自动处理:会话对象Session,该 ...

  10. call深入理解

    function fn1() { console.log(1); } function fn2() { console.log(2); } fn1.call(fn2); // 1 fn1.call.c ...