PAT 1010 Radix(X)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes
, if 6 is a decimal number and 110 is a binary number.
Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given.
Input Specification:
Each input file contains one test case. Each case occupies a line which contains 4 positive integers:
N1 N2 tag radix
Here N1
and N2
each has no more than 10 digits. A digit is less than its radix and is chosen from the set { 0-9, a
-z
} where 0-9 represent the decimal numbers 0-9, and a
-z
represent the decimal numbers 10-35. The last number radix
is the radix of N1
if tag
is 1, or of N2
if tag
is 2.
Output Specification:
For each test case, print in one line the radix of the other number so that the equation N1
= N2
is true. If the equation is impossible, print Impossible
. If the solution is not unique, output the smallest possible radix.
Sample Input 1:
6 110 1 10
Sample Output 1:
2
Sample Input 2:
1 ab 1 2
Sample Output 2:
Impossible
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 500 vector<char> vec; map<char,int> mp; ll tansss(string s,int x){
ll sum = ;
ll t = ;
for(int i=s.size()-;i>=;i--){
sum += mp[s[i]]*t;
t *= x;
}
return sum;
} int main(){
for(int i=;i <= ;i++){
vec.push_back(char(''+i));
}
for(int i=;i <= ;i++){
char temp = char('a'+(i-));
vec.push_back(temp);
} for(int i=;i < vec.size();i++){
mp[vec[i]] = i;
} // while(1){
// string s; cin >> s;
// int radix; cin >> radix;
// cout << tansss(s,radix);
// } string s1,s2;
int tag,radix;
cin >> s1 >> s2 >> tag >> radix; if(tag == ){
ll ok = tansss(s1,radix);
for(int i=;i<=;i++){
if(tansss(s2,i)==ok){
cout << i;
return ;
}
}
cout << "Impossible";
}
else{
ll ok = tansss(s2,radix);
for(int i=;i<=;i++){
if(tansss(s1,i)==ok){
cout << i;
return ;
}
}
cout << "Impossible";
} return ;
}
还要判断溢出。。。打扰了拿16分溜了
PAT 1010 Radix(X)的更多相关文章
- PAT甲组 1010 Radix (二分)
1010 Radix (25分) Given a pair of positive integers, for example, \(6\) and \(110\), can this equatio ...
- 1010 Radix (25 分)
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 1 ...
- PAT 1085 PAT单位排行(25)(映射、集合训练)
1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随 ...
- 7-07. PAT排名汇总(25) (结构体 ZJU_PAT)
题目链接:http://www.patest.cn/contests/ds/7-07 编程能力測试(Programming Ability Test,简称PAT)是浙江大学计算机科学与技术学院主办的专 ...
- PAT 1071 小赌怡情(15)(代码)
1071 小赌怡情(15 分) 常言道"小赌怡情".这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算 ...
- PAT 1058 选择题(20)(代码+思路)
1058 选择题(20 分) 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多. 输入格式: 输入在第一行给出两个正整数 N(≤ 1000)和 M(≤ 100 ...
- PAT A1010 Radix (25 分)——进制转换,二分法
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- PAT 1010 Radix (二分)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- PAT 1010 Radix (25分) radix取值无限制,二分法提高效率
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
随机推荐
- linux c(一)Helloworld
终端的屏幕上输入命令如下: 使用vi helloworld.c打开helloworld.c文件,写下如下代码:
- *.tar 用 tar –xvf 解压 *.gz 用 gzip -d或者gunzip 解压 *.tar.gz和*.tgz 用 tar –xzf 解压 *.bz2 用 bzip2 -d或者用bunzip2 解压 、*.tar.bz2用tar –xjf 解压
解压: 1.*.tar 用 tar –xvf 解压, --skip-old-files跳过已经存在的文件,压缩用tar -cvf 2.*.bz2 用 bzip2 -d或者用bunzip2 解压 3.* ...
- 框架-.NET:ASP.NET MVC
ylbtech-框架-.NET:ASP.NET MVC ASP.NET MVC 是Windows系统下面的Web研发框架,有Microsoft提供.MVC顾名思义:Model, View, Contr ...
- Oracle 用户概念与基本操作
目录 目录 Oracle的用户 通过系统用户来登陆SQLPlus system和sys的区别 查看登陆的用户 启用和锁定一个用户 启用用户 锁定用户 创建用户 修改用户 删除用户 角色权限 常用的用户 ...
- Android 发布自动版本号方案
以前看到一些自动化版本号打包的文章.如果您的项目是用 Git 管理的,并且恰巧又是使用 Gradle 编译(应该绝大部分都是这样的了吧?),本文试图找到一种更加优雅的自动版本管理方法. 背景 我们都知 ...
- Scrapy框架: pipelines.py设置
保存数据到json文件 # -*- coding: utf-8 -*- # Define your item pipelines here # # Don't forget to add your p ...
- SQL中to_char方法的应用
1.取得当前日期是本月的第几周 SQL> select to_char(sysdate,'YYYYMMDD W HH24:MI:SS') from dual; ----------------- ...
- PHP正则表达式中的反斜线
PHP反斜线再正则表达式中的使用 <?php $str = 'hello\world'; $pattern = '/hello\\\\world/'; preg_match($pattern,$ ...
- LeetCode Array Easy 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- Android 5.1 预制输入法
Android修改默认输入法为讯飞方法如下: 首先将讯飞输入法apk预制到系统app中: 在firefly-rk3288_android5.1_git_20180126/out/target/prod ...