撸完这题,感觉被掏空。

由于进制可能大的飞起。。所以需要开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. WEBROOT根目录 <%=request.getContextPath()%>

    WEBROOT根目录 <%=request.getContextPath()%> == ${pageContext.request.contextPath}

  2. 安装你自己的perl modules

    来源: http://www.cnblogs.com/itech/archive/2012/12/17/2822044.html 安装你自己的perl modules.当没有root权限的时候,需要安 ...

  3. perl模块安装

    转自: http://www.cnblogs.com/itech/archive/2009/08/10/1542832.html http://www.mike.org.cn/blog/index.p ...

  4. Java 反射实例

    实体类:Userpackage com.reflect.model; public class User{ private User(int id, String username, String p ...

  5. sql server两种分页方法

    方法一: --分页方法一 OrderID,CustomerID, EmployeeID,OrderDate,ShippedDate,ShipName,ShipAddress,Freight from ...

  6. C语言 - pthread

    pthread_create函数 原型:int  pthread_create((pthread_t  *thread,  pthread_attr_t  *attr,  void  *(*start ...

  7. 1.2 eclipse使用 :working set

    working set可以是相当于文件夹~~有多个project时, 分别存放在不同的 workingset下,可以方便管理 新建或编辑 working set时,需要记住选择project *可参照 ...

  8. 获取Excel数据(或部分数据)并导出成txt文本格式

    运行代码前先导入jxl架包,以下代码仅供参考: 测试excel文件(我要获取该excel的内容为省.县.乡.村.组和PH的值): ExcelTest01类代码如下: // 读取Excel的类 impo ...

  9. Cormen — The Best Friend Of a Man

    Cormen — The Best Friend Of a Man time limit per test 1 second memory limit per test 256 megabytes i ...

  10. 444A/CF

    题目链接[http://codeforces.com/problemset/problem/444/A] 题意:给出一个无向图,找出一个联通子图,定义密度#=v(顶点值的和)/e(边值的和). 条件: ...