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. Codeforces Round #196 (Div. 2) D. Book of Evil 树形dp

    题目链接: http://codeforces.com/problemset/problem/337/D D. Book of Evil time limit per test2 secondsmem ...

  2. 360Vedio To NFOV Vedio

    Deep 360 Pilot Learning a Deep Agent for Piloting through 360° Sports Videos 源码.数据集和视频演示 ego-centric ...

  3. C语言词频统计设计

    项目需求: 1.设计一个词频统计小软件,对给定的英文文章进行单词频率的统计. 2.文章中相应的标点不计入统计. 3.将统计结果以从大到小的排序方式输出. 设计: 1.因为功能相对简单,采用C语言直接进 ...

  4. Excelutil 工具类

    1.说明:ExcelUtil主要用于获得单元格的数据和对对指定单元格中写入数据用! 相关代码如下: package main.java; import java.io.File; import jav ...

  5. epel [Errno 14] problem making ssl connection

    问题描述: 执行yum命令时,报错[Errno 14] problem making ssl connection 问题分析: ssl证书问题 问题解决: sed -i 's/^#baseurl/ba ...

  6. Cannot create file"C:\Users\LML\AppData\Local\Temp\EditorLineEnds.ttr"。另一个程序正在使用此文件,进程无法访问。

    不能二次启动,每次开机第一次都ok,出于习惯,总是想试试第二次打开软件是否正常,结果不出所料,出现了“Cannot create file"C:\Users\LML\AppData\Loca ...

  7. using关键字

    声明导入名称空间 处理实现了IDisposeable的对象,并在作用域末尾调用Dispose方法

  8. UVAlive4080_Warfare And Logistics

    给一个无向图,求出两个值,所有点到所有其他点的最短距离和,任意删除一条边后的这个值. 数据规模是100点1000边. 白书例题,不多说了直接对于每个点求出最短路树,对于每条边,如果它不是最短路树上的边 ...

  9. UVAlive6439_Pasti Pas!

    题目是说给你一个字符串,现在要你用一些特殊的符号代替这个字符串中某一些子串,使得被替换后的串是一个回文串. 现在要你求替换后的字符串的最大的可能的长度. 其实这个题目没有什么固定的算法哦,我直接暴力就 ...

  10. python selenium2 定位一组元素find_elements实例

    打开hao123首页,需要定位以上区域中的所有链接,他们有相同的父元素<ul class="js_bd site-bd site-hd0">,所有链接处在li>a ...