当前位置:网站首页>Pat a - 1010 radical (thinking + two points)
Pat a - 1010 radical (thinking + two points)
2022-06-23 01:21:00 【S atur】
The question : It means ,tag==1, be N1 by radix Binary number ;tag==2, be N2 by radix Binary number . How many base numbers does another number have to make N1==N2, No solution output "Impossible".
Ideas : The basic idea is very simple , Directly enumerate the base of another number , Many details need to be paid attention to during the conversion of Radix . But if you enumerate directly, there will be a test point (1 branch ) Unable to get , It is not difficult to see the value of its base value, so we can query it by dichotomy , The lower limit of a binary is the maximum number of digits of another number maxx+1, Upper limit accession radix The decimal value of a decimal number +1.( If you mistake Impossible Output into impossible only 18 branch ┭┮﹏┭┮).
AC Code :
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f3f;
const int N = 1e5+10;
string a, b;
int x, y, tag, radix, maxx, ans=inf;
map<int, char> mp;
int get_int(char x){
if(isdigit(x)) return x-'0';
return x-'a'+10;
}
int to_int(string s, int k){
int res = 0;
res = get_int(s[0]);
for(int i = 1; i < s.size(); i ++){
res *= k;
res += get_int(s[i]);
}
return res;
}
bool check(int k){
int res = get_int(b[0]);
for(int i = 1; i < b.size(); i ++){
res *= k;
res += get_int(b[i]);
if(res<0||res>x) return 1;
}
if(res==x){
ans = min(ans, k);
return 1;
}
if(res<0||res>x) return 1;
else return 0;
}
signed main()
{
cin >> a >> b >> tag >> radix;
if(tag==2) swap(a, b);
x = to_int(a, radix);
for(int i = 0; i < b.size(); i ++) maxx = max(maxx, get_int(b[i]));
int l = maxx+1, r = x+1;
while(l<=r){
int mid = (l+r)>>1;
if(check(mid)) r = mid-1;
else l = mid+1;
}
if(ans==inf) cout << "Impossible" << endl;
else cout << ans << endl;
return 0;
}
边栏推荐
- 中金证券开户安全吗?它和中金银行是什么关系呢?
- Flink synchronizes MySQL data to es
- Dual cross domain: access allow origin header contains multiple values "*, *", but only one is allowed
- 层次选择器
- three. JS simulated driving tour art exhibition hall - creating super camera controller
- 最安全的现货白银的心理分析
- Project directory navigation
- How to set the power-off auto start of easycvr hardware box
- Similar to attention NLP
- "Hearing" marketing value highlights, Himalaya ushers in a new situation
猜你喜欢

黄金etf持仓量如何算

Sfod: passive domain adaptation and upgrade optimization, making the detection model easier to adapt to new data

3D打印微组织

How do beginners get started quickly and learn deeply?

Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe

BGP federal comprehensive experiment

OSPF experiment in mGRE environment

Webdriver and selenium Usage Summary

層次選擇器

一文读懂基于Redis的Amazon MemoryDB数据库
随机推荐
Vector 6 (inheritance)
Learn the specific technical learning experience of designing reusable software from the three levels of class, API and framework
Have you stepped on these pits? Use caution when creating indexes on time type columns
Quelle est la structure et la façon dont les données sont stockées dans la base de données?
C# SerializableDictionary序列化/反序列化
Hello, is the securities account presented by the Business School of qiniu business school safe? How can I open a safe stock account to speculate in stocks
C#. Net universal database access encapsulation classes (access, sqlserver, Oracle)
TiDB VS MySQL
How to set the power-off auto start of easycvr hardware box
Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines
层次选择器
Ansible learning summary (7) -- ansible state management related knowledge summary
SAP mm transaction code vl04 create outbound delivery for sto
MGRE环境下的OSPF实验
leetcode 91. Decode Ways 解码方法(中等)
3D打印微组织
BGP联邦综合实验
Cadence spb17.4 - Chinese UI settings
“听觉”营销价值凸显,喜马拉雅迎来新局点
Big guys, 2.2.1 the CDC monitoring SQLSEVER can only get the full amount of data. Why can't we get the incremental data in the later period