https://www.patest.cn/contests/pat-a-practise/1010

题目大意:

输入四个数字,a,b,c,d。

a和b是两个数字,c=1表示是第一个数字,c=2表示是第二个数字,d表示该数字是几进制

问:a和b是否能在某一进制下相等

思路:

傻逼二分...

一年没写过了,细节思考竟然差了这么多,尴尬了...

 //看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 1e5 + ;
LL val;
char ch1[maxn], ch2[maxn]; LL get_int(char ch){
if (ch >= '' && ch <= '') return 1LL * (ch - '');
return 1LL * (ch - 'a' + );
}
//c 1100 1 26
bool flag;
LL cal(LL x, int n){
LL ans = ; while (n){
if (n & ) ans *= x;
x = x * x;
if (x < || ans < ) flag = false;
n /= ;
}
return ans;
} LL get_val(vector<LL> ve, int radix){
LL sum = ;
int cnt = ;
for (int i = ve.size() - ; i >= ; i--){
sum = sum + ve[i] * cal(1LL * radix, cnt);
cnt++;
}
if (sum < ) flag = false;
return sum;
} bool solve(vector<LL> b){
LL lb = , rb = val + ;
for (int i = ; i < b.size(); i++)
lb = max(lb, b[i] + );
while (lb < rb){
LL mid = (lb + rb) / ;
flag = true;
LL tmp = get_val(b, mid);
if (!flag) {
rb = mid - ; continue;
}
if (val > tmp) lb = mid + ;
if (val < tmp) rb = mid - ;
if (val == tmp) rb = mid;
}
if (get_val(b, lb) == val) {
printf("%lld\n", lb);
return true;
}
return false;
} int main(){
scanf("%s%s", ch1, ch2);
int ty, change;
scanf("%d%d", &ty, &change);
vector<LL> a, b;
if (ty == ){
for (int i = ; ch1[i] != '\0'; i++)
a.push_back(get_int(ch1[i]));
for (int i = ; ch2[i] != '\0'; i++)
b.push_back(get_int(ch2[i]));
}
else {
for (int i = ; ch2[i] != '\0'; i++)
a.push_back(get_int(ch2[i]));
for (int i = ; ch1[i] != '\0'; i++)
b.push_back(get_int(ch1[i]));
}
val = get_val(a, change);
if(!solve(b)) puts("Impossible");
return ;
}

已经菜到不行了 PAT 1010. Radix (25)的更多相关文章

  1. PAT 1010 Radix (25分) radix取值无限制,二分法提高效率

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

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

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

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

  4. pat 甲级 1010. Radix (25)

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

  5. PAT 1010 Radix(X)

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

  6. PAT (Advanced Level) 1010. Radix (25)

    撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...

  7. 1010. Radix (25) pat

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

  8. PAT Advanced 1010 Radix(25) [⼆分法]

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

  9. PAT甲题题解-1010. Radix (25)-二分搜索

    题意:给出n1和n2,以及其中一个数的进制,问另一个数是多少进制的情况下,才会是两个数相等.不存在的话,则输出Impossible 这题思路很简单,但是要考虑的比较多,在简单题里面算是比较好的. 有两 ...

随机推荐

  1. 一个简单的加减乘除自动生成小程序升级版(JAVA)

    import java.util.Scanner; public class Suan { public static void main(String[] args) { int []b;//设置数 ...

  2. Week2-作业1 《构建之法》1、2、16章观后感

    这几天阅读了<构建之法>中的几章,受益匪浅,刷新了很多我对软件工程的认知.这本书让我很惊喜,阅读起来不像其他书一样枯燥,有很多人物的设计,以及对话的形式,非常有趣. 第一章.概述 读完第一 ...

  3. java synchronized关键字浅析

    synchronized这个关键字想必学Java的人都应该知道. 直接上例子: 方法级别实例 public class AtomicInteger { private int index; publi ...

  4. cobbler-web 界面技术详解

    cobbler-web安装配置过程详解 (1)安装cobbler-web(测试时候,确保物理网络是在内网中进行,在外网会无法访问的哦,cobbler-web的访问入口必须有dhcpd指定的网络保持一致 ...

  5. 第九周(11.11-11.17)----Beta版本发布140字评论

    1.新蜂组: 俄罗斯方块:项目有良好的用户界面,在原版的基础上可以对用户分数进行排序,增加了显示下一个方块的功能.是个很有趣的小游戏. 2.天天向上组: 连连看:完成了基本功能,增加了消除时和鼠标点击 ...

  6. 使用JavascriptExecutor将页面滚动到最底部

    使用如下代码,将页面滚动到最底部 @Test(enabled = true) public void scroll(){ String jsStr="window.scrollTo(0,do ...

  7. 总结MySQL修改最大连接数的两个方式

    最大连接数是可以通过mysql进行修改的,mysql数据库修改最大连接数常用有两种方法,今天我们分析一下这两种方法之间的特点和区别,以便我们能更好的去维护mysql.下面我们来看一下mysql修改最大 ...

  8. [51CTO]给您介绍Windows10各大版本之间区别

    给您介绍Windows10各大版本之间区别 随着win10的不断普及和推广,越来越多的朋友想安装win10系统了,但是很多朋友不知道win10哪个版本好用,为了让大家能够更好的选择win10系统版本, ...

  9. iptables 开放端口

    #iptables -A INPUT -p tcp --dport 5000 -j ACCEPT #service iptables save

  10. 2013成都网赛1010 hdu 4737 A Bit Fun

    题意:定义f(i, j) = ai|ai+1|ai+2| ... | aj (| 指或运算),求有多少对f(i,j)<m.1 <= n <= 100000, 1 <= m &l ...