PAT (Advanced Level) 1010. Radix (25)
撸完这题,感觉被掏空。
由于进制可能大的飞起。。所以需要开longlong存,答案可以二分得到。
进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid-1
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std; char s[],t[];
int tag;
long long radix;
long long num1,num2; long long f(char *x,long long k)
{
int len=strlen(x);
long long ans=;
for(int i=;x[i];i++)
{
ans=ans*k;
if(x[i]>=''&&x[i]<='') ans=ans+x[i]-'';
else ans=ans+x[i]-'a'+;
if(ans<) return -;
}
return ans;
} int main()
{
scanf("%s%s%d%lld",s,t,&tag,&radix);
if(tag==) swap(s,t);
int lens=strlen(s),lent=strlen(t); num1=f(s,radix); long long l=,r=num1+; for(int i=;t[i];i++)
{
if(t[i]>=''&&t[i]<='') l=max(l,(long long)(t[i]-''+));
else l=max(l,(long long)(t[i]-'a'++));
} long long ans;
bool flag=; while(l<=r)
{
long long mid=(l+r)/;
long long num2=f(t,mid); if(num2<) r=mid-;
else if(num1>num2) l=mid+;
else if(num1<num2) r=mid-;
else
{
ans=mid;
flag=;
break;
}
} if(flag== ) printf("%lld\n",ans);
else printf("Impossible\n");
return ;
}
PAT (Advanced Level) 1010. Radix (25)的更多相关文章
- PAT 解题报告 1010. Radix (25)
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
- PTA (Advanced Level) 1010 Radix
Radix Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? ...
- PAT (Advanced Level) 1078. Hashing (25)
二次探测法.表示第一次听说这东西... #include<cstdio> #include<cstring> #include<cmath> #include< ...
- PAT (Advanced Level) 1070. Mooncake (25)
简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...
- PAT (Advanced Level) 1029. Median (25)
scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...
- PAT (Advanced Level) 1003. Emergency (25)
最短路+dfs 先找出可能在最短路上的边,这些边会构成一个DAG,然后在这个DAG上dfs一次就可以得到两个答案了. 也可以对DAG进行拓扑排序,然后DP求解. #include<iostrea ...
- PAT (Advanced level) 1003. Emergency (25) Dijkstra
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT (Advanced Level) 1032. Sharing (25)
简单题,不过数据中好像存在有环的链表...... #include<iostream> #include<cstring> #include<cmath> #inc ...
- 【PAT甲级】1010 Radix (25 分)(二分)
题意: 输入两个数可能包含小写字母,1或者2,进制大小.第三个数为代表第一个数是第四个数进制的,求第二个数等于第一个数时进制的大小,不可能则输出Impossible,第三个数为2代表第二个数是第四个数 ...
随机推荐
- kubernetes 留言版DEMO
kubernates hello world1 关闭防火墙 $systemctl disable firewalld $systemctl stop firewalld 2 安装etcd 和 kube ...
- React和动态网站接口的经济学
来自: React and the economics of dynamic web interfaces 自从2000开始我就一直在做web开发,曾见过很多以各种库和框架的起起落落,这些库和框架作为 ...
- 判断数字 字母 isDigit(), isalpha()
判断是否是数字 isdigit isNumber 二者区别http://www.cnblogs.com/xiashengwang/p/3219925.html 需要包含头文件 #i ...
- three dot
http://stackoverflow.com/questions/28031603/what-do-three-dots-mean-in-go-command-line-invocations
- C++中的函数指针和函数对象总结
篇一.函数指针函数指针:是指向函数的指针变量,在C编译时,每一个函数都有一个入口地址,那么这个指向这个函数的函数指针便指向这个地址.函数指针的用途是很大的,主要有两个作用:用作调用函数和做函数的参数. ...
- php杂乱
// // if ( $_GET['action'] == 'search' ) {// $_clean = array();// $_clean['stype ...
- CodeIgniter 如何去掉 Index.php
步骤; 1.打开你的WEB服务器的httpd.conf文件. 2.找到LoadModule rewrite_module modules/mod_rewrite.so这行,把该行前的#去掉.保存该文件 ...
- 二叉树,平衡树,红黑树,B~/B+树汇总
二叉查找树(BST),平衡二叉查找树(AVL),红黑树(RBT),B~/B+树(B-tree).这四种树都具备下面几个优势: (1) 都是动态结构.在删除,插入操作的时候,都不需要彻底重建原始的索引树 ...
- Entity Framework 学习初级篇3-- LINQ TO Entities
LINQ 技术(即 LINQ to Entities)使开发人员能够通过使用 LINQ 表达式和 LINQ 标准查询运算符,直接从开发环境中针对 实体框架对象上下文创建灵活的强类型查询.LINQ to ...
- css div inline 与 span 区别
不是说用了display:lnline就变内联原素 和span有区别更奇怪的是ff里面执行就没区别 <span style="">xxx</span> &l ...