当前位置:网站首页>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;
}
边栏推荐
- Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines
- Get the start and end dates of the current week
- Vector 6 (inheritance)
- 总体标准差和样本标准差
- Extend your kubernetes API using the aggregation API
- Tidb monitoring upgrade: a long way to solve panic
- New progress in the construction of meituan's Flink based real-time data warehouse platform
- I've been outsourcing for four years, but I feel it's useless
- Software construction course ADT and OOP understanding
- 人民币的单位的大写
猜你喜欢
Voice network multiplayer video recording and synthesis support offline re recording | Nuggets technology solicitation

How to solve the problem that easycvr does not display the interface when RTMP streaming is used?

【滑动窗口】leetcode992. Subarrays with K Different Integers

层次选择器

Steps to implement a container global component
![[machine learning watermelon book] update challenge [Day1]: 1.1 INTRODUCTION](/img/f6/b0df192502a59a32d8bac8c0862d02.png)
[machine learning watermelon book] update challenge [Day1]: 1.1 INTRODUCTION

Webdriver and selenium Usage Summary

How about precious metal spot silver?

贵金属现货白银如何呢?

A hundred lines of code to realize reliable delay queue based on redis
随机推荐
Which platform is safer to buy stocks on?
You can also do NLP (classification)
Yyds dry goods counting tail recursion is better than recursion
It's still like this
中金证券开户安全吗?它和中金银行是什么关系呢?
New progress in the construction of meituan's Flink based real-time data warehouse platform
07 project cost management
How to calculate the position of gold ETF
SAP ui5 application development tutorial 103 - how to consume third-party libraries in SAP ui5 applications
Overview of visual object detection technology based on deep learning
JMeter associated login 302 type interface
Quelle est la structure et la façon dont les données sont stockées dans la base de données?
Hierarchy selector
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
What financial product does the new bond belong to?
Requête linq
Is it reliable to get new debts? Is it safe?
Sélecteur de hiérarchie
OSPF comprehensive experiment
TiDB VS MySQL