1010. Radix (25)
2015-11-04 12:33
369 查看
1.此题较为重点
2.最小的radix为各位的数字最大值+1
3.采用二分法查找,l=radix,r=已知的数+1
4.要求的最大radix不一定是36
2.最小的radix为各位的数字最大值+1
3.采用二分法查找,l=radix,r=已知的数+1
4.要求的最大radix不一定是36
//#include<string> //#include <iomanip> #include<vector> #include <algorithm> //#include<stack> #include<set> #include<queue> #include<map> //#include<unordered_set> //#include<unordered_map> //#include <sstream> //#include "func.h" //#include <list> #include<stdio.h> #include<iostream> #include<string> #include<memory.h> #include<limits.h> using namespace std; int main(void) { string n1, n2; int tag; unsigned long long radix; cin >> n1 >> n2 >> tag >> radix; string s, t; if (tag == 1) { s = n1; t = n2; } else if (tag == 2) { s = n2; t = n1; } unsigned long long sInt = 0; for (int i = 0; i < s.size(); i++) {//把s转为十进制 sInt = sInt*radix + c2int(s[i]); } unsigned long long minRadix = 2; for (int i = 0; i < t.size(); i++) {//求出最小的进制数 minRadix = max(minRadix, c2int(t[i]) + 1); } bool flag = false; unsigned long long result = 0; unsigned long long r = sInt + 1;//必须+1 unsigned long long l = minRadix; while (l <= r)//必须要有等号!! {//从最小的进制数开始遍历 unsigned long long j = (l + r) / 2;//没说明j最大是36进制 unsigned long long tInt = 0; for (int i = 0; i < t.size(); i++) { tInt = tInt*j + c2int(t[i]); if (tInt > sInt) { break; } } if (tInt == sInt) { flag = true; result = j; break; } else if (tInt > sInt) { r = j - 1; /*flag = false; break;*/ } else l = j + 1; } if (flag) cout << result << endl; else cout << "Impossible" << endl; return 0; }
相关文章推荐
- 线程池
- 网络安全形势复杂,专利积累成第一要务
- java中关于文本文件的读写方法实例总结
- 你真的会玩SQL吗?Case的用法(转)
- htm跨域锚点定位
- Android Camera 调用流程总结
- 1009. Product of Polynomials (25)
- [OpenJudge-NOI]神奇序列求和
- UIApplication常用的代理方法和属性
- 1009. Product of Polynomials (25)
- 一加手机发力小屏做行业逆行者
- [OpenJudge-NOI]最大公约数与最小公倍数
- android模拟器与PC的端口映射(转)
- Oracle丢失重做日志的几种场景恢复
- 201511041227_《JavaScript——动态原型对象(优化写法)》
- Linux下配置安装PHP环境
- 周鸿祎携奇酷手机999元“射杀”行业暴利
- 1007. Maximum Subsequence Sum (25)
- javaWeb--API 自动化测试框架分享
- POJ——3253 Fence Repair(优先队列)