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. \0 的ASCII码值是多少

    \0 的ASCII码值是多少 #include<iostream> using namespace std; void main() { char c = '\0'; cout<&l ...

  2. 由RS-232串口到PROFIBUS-DP总线的转换接口设计

    转自:http://gongkong.ofweek.com/2013-08/ART-310007-11001-28716256_2.html 1.PROFIBUS-DP网络协议 PROFIBUS的网络 ...

  3. windows下的C++ socket服务器(3)

    int make_server_socket(int port) { WSADATA inet_WsaData; WSAStartup(MAKEWORD(), &inet_WsaData); ...

  4. vue 实战 遇到问题记录

    vue-router  配置路由遇到问题 1.一个 new Router({ routes:[ { path:'/', component:Good    ///不要写成components  否则报 ...

  5. 电脑CPU开机上电后的第一条指令

    结合上面的文章,CPU上电后第一条指令是通过CS:IP来指定的,CPU厂家会给其初始值,对于386处理器来说,CPU第一条指令地址是 0xFFFFFFF0 这里会有一个问题,CPU怎么能一上来就去0x ...

  6. [转帖]从HTTP/0.9到HTTP/2:一文读懂HTTP协议的历史演变和设计思路

    从HTTP/0.9到HTTP/2:一文读懂HTTP协议的历史演变和设计思路   http://www.52im.net/thread-1709-1-2.html     本文原作者阮一峰,作者博客:r ...

  7. jQuery : 有关TypeError: invalid ‘in’ operand obj的错误

    参考 lwx2615 的博客 ,网站:  http://blog.csdn.net/lwx2615/article/details/9668777 由PHP返回一个json数据 $.ajax({ ur ...

  8. 动态生成lookup字段

    var  i: Integer;begin  //ADOQuery已打开   //在数据集打开的情况下新增加一个字段  with Self.ADOQuery1 do  begin    TDataSe ...

  9. DAY2-Flask项目

    回顾: 1.安装pipenv虚拟运行环境,隔离项目 (启动:pipenv shell) 2.安装flask(pipenv install shell),查看项目依赖(pipenv graph) 3.查 ...

  10. 3.11 - 3.12 A day with Google

    补了一番游记. 找了一个本科学弟一起去上海游玩.本来老板还要我周一过去讨论寒假阅读的论文,总算是把讨论时间挪到周六了. 兴冲冲地买好车票后就开始期待上海Google office的神秘之旅. upda ...