改了一天也没明白,第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. 理解JWT(JSON Web Token)认证

    理解JWT(JSON Web Token)认证 最近想做个小程序,需要用到授权认证流程.以前项目都是用的 OAuth2 认证,但是Sanic 使用OAuth2 不太方便,就想试一下 JWT 的认证方式 ...

  2. 普通平衡树 lg3369

    在多次学习splay后,我终于理解并码出了整份代码 参考了https://tiger0132.blog.luogu.org/slay-notes的博客 具体实现原理在上面这篇博客和百度中可以查到,接下 ...

  3. Python之旅的开始day1

    Python有哪些种类: JPython.IronPython.JavaScriptPython.RubyPython.CPython(即将开始学习种类,最为常见的种类).pypy pypy:这是用C ...

  4. Codeforces Hello2020 A-E简要题解

    contest链接:https://codeforces.com/contest/1284 A. New Year and Naming 思路:签到,字符串存一下,取余拼接. #include< ...

  5. codeforces 1283E New Year Parties (贪心)

    链接:https://codeforces.com/contest/1283/problem/E 题意: 有n个人住在一些房子里,有的人住在同一个房子里.每个人可以选择搬去他的房子左边那个房子或者右边 ...

  6. 140. 单词拆分 II

    Q: 给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,在字符串中增加空格来构建一个句子,使得句子中所有的单词都在词典中.返回所有这些可能的句子. 说明: 分隔时可以重复使用字典 ...

  7. HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out的解决方法

    问题描述: Pycharm创建Django项目提示:HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed o ...

  8. 第三十四篇 玩转数据结构——哈希表(HashTable)

    1.. 整型哈希函数的设计 小范围正整数直接使用 小范围负整数整体进行偏移 大整数,通常做法是"模一个素数"   2.. 浮点型哈希函数的设计 转成整型进行处理   3.. 字符串 ...

  9. VMare安装及虚拟机的安装

    VMware安装 1.下载安装包安装 2.安装虚拟机 ![](ht p 接下来的开启虚拟机按照默认的配置 install or upgrade an existing system skip(选择跳过 ...

  10. webpack4.41.0配置一(基础配置webpack文件,入口出口,实现打包)

    1.查看node.js版本.npm版本和webpack版本(使用webpack4时,请确保node.js的版本>=8.9.4) 2.我先重新卸载了webpack和webpack-cli(全局) ...