已经菜到不行了 PAT 1010. Radix (25)
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)的更多相关文章
- PAT 1010 Radix (25分) radix取值无限制,二分法提高效率
		
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
 - PAT 解题报告 1010. Radix (25)
		
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
 - 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 ...
 - pat 甲级 1010. Radix (25)
		
1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...
 - PAT 1010 Radix(X)
		
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = ...
 - PAT (Advanced Level) 1010. Radix (25)
		
撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...
 - 1010. Radix (25) pat
		
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
 - PAT Advanced 1010 Radix(25) [⼆分法]
		
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
 - PAT甲题题解-1010. Radix (25)-二分搜索
		
题意:给出n1和n2,以及其中一个数的进制,问另一个数是多少进制的情况下,才会是两个数相等.不存在的话,则输出Impossible 这题思路很简单,但是要考虑的比较多,在简单题里面算是比较好的. 有两 ...
 
随机推荐
- angularJS1笔记-(15)-自定义指令(accordion伸缩菜单原始实现)
			
index.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
 - vue 中使用better-scroll 遇到的问题
			
以下是遇到问题以及解决方法 1.使用v-for 循环循环出来的列表,不能滚动. 原因是没有给wrapper 父层 加高度,当子层的高度大于父层的高度,才能滚动 打印scroll 对象,显示如此 竟然相 ...
 - 理解jquery on 委托事件的机制
			
前两天做了一个点击任意位置,都能关闭菜单的功能,因为菜单里面的每一个a,的点击事件都是用on绑定的.所以在阻止冒泡的时候不管用,今天特意来理解一下on的机制 on 是委托事件,利用的就是冒泡原理 $( ...
 - Scrum 项目 4.0-5.0-约教网站开发(一)
			
----------------------------------4.0----------------------------------------------- 一.项目任务 1.准备看板. ...
 - Beta阶段——3
			
一.提供当天站立式会议照片一张: 二. 每个人的工作 (有work item 的ID) (1) 昨天已完成的工作: 今天主要是对管理员功能进行改进,解决了Alpha阶段出现的一些问题 (2) 今天计划 ...
 - CSS和JS引用图片(资源)的路径问题
			
做项目时遇到了这个问题,特此写个笔记记一下
 - Selenium WebDriver 中鼠标和键盘事件分析及扩展(转)
			
文章转自:http://www.ibm.com/developerworks/cn/java/j-lo-keyboard/
 - Genymotion-ARM-Translation_v1.1安装报“an error occured while deploying the file”
			
如上图,在将Genymotion-ARM-Translation_v1.1.zip拖动Genymotion虚拟机中报了图中错误,在百度后找到了解决办法,下面是我的操作步骤 1.下载re管理器之类的ap ...
 - git使用教程推荐
			
Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是 ...
 - Js 中的原始值和引用值
			
最近遇写 node.js 时到一个问题,把对象当赋值给数组成员时总是出错,比如下面的代码, var Arr = new Array(); var Obj = new Object(); for(var ...