撸完这题,感觉被掏空。

由于进制可能大的飞起。。所以需要开longlong存,答案可以二分得到。

进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid-1

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std; char s[],t[];
int tag;
long long radix;
long long num1,num2; long long f(char *x,long long k)
{
int len=strlen(x);
long long ans=;
for(int i=;x[i];i++)
{
ans=ans*k;
if(x[i]>=''&&x[i]<='') ans=ans+x[i]-'';
else ans=ans+x[i]-'a'+;
if(ans<) return -;
}
return ans;
} int main()
{
scanf("%s%s%d%lld",s,t,&tag,&radix);
if(tag==) swap(s,t);
int lens=strlen(s),lent=strlen(t); num1=f(s,radix); long long l=,r=num1+; for(int i=;t[i];i++)
{
if(t[i]>=''&&t[i]<='') l=max(l,(long long)(t[i]-''+));
else l=max(l,(long long)(t[i]-'a'++));
} long long ans;
bool flag=; while(l<=r)
{
long long mid=(l+r)/;
long long num2=f(t,mid); if(num2<) r=mid-;
else if(num1>num2) l=mid+;
else if(num1<num2) r=mid-;
else
{
ans=mid;
flag=;
break;
}
} if(flag== ) printf("%lld\n",ans);
else printf("Impossible\n");
return ;
}

PAT (Advanced Level) 1010. Radix (25)的更多相关文章

  1. PAT 解题报告 1010. Radix (25)

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

  2. PTA (Advanced Level) 1010 Radix

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

  3. PAT (Advanced Level) 1078. Hashing (25)

    二次探测法.表示第一次听说这东西... #include<cstdio> #include<cstring> #include<cmath> #include< ...

  4. PAT (Advanced Level) 1070. Mooncake (25)

    简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...

  5. PAT (Advanced Level) 1029. Median (25)

    scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...

  6. PAT (Advanced Level) 1003. Emergency (25)

    最短路+dfs 先找出可能在最短路上的边,这些边会构成一个DAG,然后在这个DAG上dfs一次就可以得到两个答案了. 也可以对DAG进行拓扑排序,然后DP求解. #include<iostrea ...

  7. PAT (Advanced level) 1003. Emergency (25) Dijkstra

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  8. PAT (Advanced Level) 1032. Sharing (25)

    简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...

  9. 【PAT甲级】1010 Radix (25 分)(二分)

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

随机推荐

  1. android--屏幕旋转方法总结

    在介绍之前,我们需要先了解默认情况下android屏幕旋转的机制: 默认情况下,当用户手机的重力感应器打开后,旋转屏幕方向,会导致当前activity发生onDestroy-> onCreate ...

  2. css 相关

    background-size: auto就会变成就是不会让图像变形的,会自动调整,一般是会设置多少箱像素的, background-size: XXpx XXpx;百分百那就铺满整个区域了 back ...

  3. C#获取本机局域网ip和公网ip

    1.获取局域网ip IPAddress ipAddr = Dns.Resolve(Dns.GetHostName()).AddressList[0];//获得当前IP地址 string ip=ipAd ...

  4. web项目的集成测试:模拟点击

    利用模拟点击的方式进行集成测试,我们准备用google,Firefox和ie三种浏览器测试. 其中除了Firefox是模拟点击的鼻祖不需要插件外,谷歌和ie需要另外下载插件 chromedriver. ...

  5. JPA 系列教程1-环境搭建

    JPA JPA全称Java Persistence API. JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. Hibernate3.2+.Top ...

  6. 【HDU 5833】Zhu and 772002(异或方程组高斯消元讲解)

    题目大意:给出n个数字a[],将a[]分解为质因子(保证分解所得的质因子不大于2000),任选一个或多个质因子,使其乘积为完全平方数.求其方法数. 学长学姐们比赛时做的,当时我一脸懵逼的不会搞……所以 ...

  7. [转]LayoutInflater的inflate函数用法

    LayoutInflater作用是将layout的xml布局文件实例化为View类对象. 获取LayoutInflater的方法有如下三种: LayoutInflater inflater=(Layo ...

  8. RedHat Enterprise Linux AS4&5 安装gcc过程

    三.Gcc安装方法(redhat 4): 一.安装步骤 1.使用which gcc命令查看gcc是否安装安装 2.如若没有安装则下载如下安装包,所需安装包如下 一共需要拷贝以下五个安装包: binut ...

  9. Datatable.select() 方法的使用

    文章为转载 ,原文地址 DataTable是我们在进行开发时经常用到的一个类,并且经常需要对DataTable中的数据进行筛选等操作,下面就介绍一下Datatable中经常用到的一个方法--Selec ...

  10. CentOS服务端口开放

    #例如开放81端口iptables -I INPUT -i eth0 -p tcp --dport 81 -j ACCEPTiptables -I OUTPUT -o eth0 -p tcp --sp ...