改了一天也没明白,第7个数据是怎么卡的

#include <bits/stdc++.h>
using namespace std;
const int maxn=1005;
typedef long long ll; ll tonum(char c)
{
if (c>='0'&&c<='9') {
return c-'0';
}
return c-'a'+10;
} long long tran(string s,ll base)
{
int len=s.length();
ll res=0;
for (int i=0;i<len;i++) {
res=res*base+tonum(s[i]);
}
return res;
} int main()
{
int tag,base;
string a,b;
cin>>a>>b>>tag>>base;
if (tag==2) {
swap(a,b);
}
ll numa=tran(a,base);
ll left=2,right=numa+1;
int len=b.length();
for (int i=0;i<len;i++) {
left=max(left,tonum(b[i])+1);
}
// printf("%lld %lld\n",left,right);
while (left<=right) {
ll mid=(right+left)>>1;
// printf("%lld\n",mid);
ll t=tran(b,mid);
if (t<0||t>=numa) right=mid-1;
else left=mid+1;
}
if (tran(b,left)==numa) {
printf("%lld\n",left);
}
else {
printf("Impossible");
}
return 0;
}

1010 Radix (25分)的更多相关文章

  1. 1010 Radix (25 分),PTA

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805507225665536 题意:给定n1.n2两个数,求可以是两 ...

  2. 1010 Radix (25 分)

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

  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 (25分) radix取值无限制,二分法提高效率

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

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

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

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

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

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

  8. pat 甲级 1010. Radix (25)

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

  9. 1010. Radix (25)(未完成)

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

随机推荐

  1. python 深浅copy总结

    总结: ''' 总结:假设l1为原数据,l2为deepcopy后的数据: 1.浅copy,只能改变第一层的内存地址(不可变数据类型除外). 2.深copy,能够改变第一层和第二层的内存地址(不可变数据 ...

  2. C++-POJ1995-Raising Modulo Numbers[快速幂]

    #include <cstdio> typedef long long ll; int quick_pow(ll a,ll b,ll mod){ ll ans=; ))ans=(ans*a ...

  3. JavaScript的严格检查模式

    JavaScript的严格检查模式 前提:IDEA设置为ECMAScript 6语法. 'use strict':严格检查模式,用来预防JS的随意性导致的问题. 比如:直接 i=1;这样定义成了全局变 ...

  4. 【HTML】iframe嵌套界面自适应,可高度自由收缩

    最近在做网页时需要使iframe高度自适应,以提高用户体验,网上找了挺多都很复杂,最后找到了这个 HTML: <div class="main_page"> <i ...

  5. 变色html css js

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  6. js处理json字符串

    后台输出的字符串为 res= {"result":"true","data":"提交成功"} 前台js无法转化成对象,需 ...

  7. AcWing 803. 区间合并

    #include <iostream> #include <vector> #include <algorithm> using namespace std; ty ...

  8. MarkDown的黄金搭档Typora编辑器

    让你成为热爱写作的程序员 学习编程的小伙伴,要养成记笔记的好习惯,并发布到博客上去与同行分享你的学习经验,那么传统的文本编辑器或多或少会不尽人意,效率低,而且码字体验与写代码完全不一样. 下面推荐一款 ...

  9. [控制台尊享] MinGW下使用 gotoxy函数

    相信用过Turbo C的童鞋都知道gotoxy这个函数吧,但由于某些原因,windows下的mingw没有直接提供这个函数. 那么gotoxy究竟是干什么的呢?假设你的程序是基于控制台的(就是一个黑窗 ...

  10. python 小故事1

    def test(a:str,b:int)->str: print(test.__annotations__) return a+str(b) def doc_print(): "&q ...