撸完这题,感觉被掏空。

由于进制可能大的飞起。。所以需要开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. Spring Security3实现,权限动态获取

    Spring Security3实现,权限动态获取 原文  http://blog.csdn.net/yangwei19680827/article/details/9359113 主题 网络安全Sp ...

  2. app调用支付宝支付 笔记

    1.提交各种申请 2.通过后进入支付宝开放平台  --> 管理中心 -->创建应用  --> 填写相关信息 提交等待审核通过(1,2天)   3.下载集成包(https://doc. ...

  3. 并查集+bfs+暴力滑窗 Codeforces Round #356 (Div. 2) E

    http://codeforces.com/contest/680/problem/E 题目大意:给你一个n*n的图,然后图上的 . (我们下面都叫做‘点’)表示可以走,X表示不能走,你有如下的操作, ...

  4. perl中调用cgi

    来源: http://www.cnblogs.com/itech/archive/2012/09/23/2698856.html 参考:http://www.willmaster.com/librar ...

  5. 打不开BT,一直重复的关闭开启。

    /bt-btif (25335): ...preload_wait_timeout (retried:0/max-retry:1)...D/bt_userial(25335): RX terminat ...

  6. 判断是ios还是android

    //判断是ios还是androidvar system;var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test( ...

  7. php过滤HTML标签、属性等正则表达式汇总

    $str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...

  8. C++调用com控件方法

    转载自:http://blog.csdn.net/haijun286972766/article/details/6273414 最近要求做一个C++调用com组件的DEMO.由于自己对C++并无研究 ...

  9. (一)Python之猜数游戏

    猜数游戏由简如深的编码学习过程: 3次机会: print('------------------我爱鱼C工作室------------------')count=0while count < 3 ...

  10. swift(2)元祖(Tuple)

    let somePoint = (, ) switch somePoint { , ): // 位于远点 println("(0, 0) is at the origin") ): ...