PAT 1010 Radix
个人学习记录,代码难免不尽人意
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 N 1and N 2, 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<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const ll inf=(1ll << 63)-1;
int chartoint(char ch){if(ch>='0'&&ch<='9') return ch-'0';else return ch-'a'+10;
}
ll converttoten(string str,ll radix){ll num=0;for(int i=0;i<str.size();i++){num=num*radix+chartoint(str[i]);}if(num<0||num>inf) return -1;return num;
}
int cmp(string n2,ll radix,ll num1){ll num2=converttoten(n2,radix);if(num2<0) return 1;if(num1>num2) return -1;if(num1==num2) return 0;if(num1<num2) return 1;
}
ll binarysearch(string n2,ll left,ll right,ll num1){ll mid;while(left<=right){mid=(left+right)/2;int flag=cmp(n2,mid,num1);if(flag==1) right=mid-1;else if(flag==-1) left=mid+1;else return mid;}return -1;
}
int main(){int tag;ll radix;string n1,n2;cin >> n1 >>n2 >> tag >> radix;if(tag!=1){string temp=n1;n1=n2;n2=temp;}ll num1=0,num2=0;num1=converttoten(n1,radix);ll low=1;for(int i=0;i<n2.size();i++){if(chartoint(n2[i])>low) low=chartoint(n2[i]);}low++;ll upper=max(low,num1)+1;ll res=binarysearch(n2,low,upper,num1);if(res==-1) printf("Impossible\n");else printf("%lld\n",res);return 0;}
这道题很有难度,建议参考《算法笔记》。
相关文章:
PAT 1010 Radix
个人学习记录,代码难免不尽人意 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 N 1and N 2…...
ruoyi-cloud微服务新建子模块
目录 相关文章1、复制system模块2、在modules下的 pom.xml文件中添加子模块 test3、进入 test模块修改 pom.xml4、修改对应的包名、目录名和启动应用程序为test5、修改bootstrap.yml文件中的端口号和应用名称6、nacos中克隆 system-dev.yml的配置,修改名称为 test-d…...
Dijkstra(求最短路)
时间复杂是 O(n2m) ,n 表示点数,m 表示边数 模板(朴素法一般m等于n^2的时候使用) #include<bits/stdc.h> #include<algorithm> using namespace std; const int N510; int g[N][N]; //为稠密阵所以用邻接矩阵存储 int dist[N]; //用…...
React 脚手架
1.React 定义 React 脚手架(React boilerplate)是一种预先设置好的、可以快速启动 React 项目的工具。脚手架已经包含了 React、Webpack、Babel、ESLint、Jest 等一些常用的工具和库,并已经配置好了这些工具的参数,可以直接使用和…...
CTFSHOW php命令执行
目录 web29 过滤flag web30 过滤system php web31 过滤 cat|sort|shell|\. 这里有一个新姿势 可以学习一下 web32 过滤 ; . web33 web34 web35 web36 web37 data伪协议 web38 短开表达式 web39 web40 __FILE__命令的扩展 web41 web42 重定向…...
侧滑置顶,取消置顶
第一步:布局 <?xml version"1.0" encoding"utf-8"?> <com.ddmh.magic.camera.ui.widget.SwipeMenuLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.com/apk/res-auto"…...
Pycharm解决启动时候索引慢的问题
设置里去掉update里面的两个勾 shared indexes中,把自动下载索引改成不下载使用本地索引...
Http请求响应时间一般划分标准
HTTP请求的响应时间被认为是长或短通常取决于具体应用场景和性能需求。一般来说,以下是一些常见的对HTTP请求响应时间进行划分的标准: 即时响应:通常在毫秒级别的响应时间被认为是即时响应。这适用于对实时性要求较高的应用,如实时…...
生成测试报告,在Unittest框架中就是简单
测试套件(Test Suite)是测试用例、测试套件或两者的集合,用于组装一组要运行的测试(多个测试用例集合在一起)。 (1)创建一个测试套件: import unittest suite unittest.TestSuite…...
生成式人工智能的潜在有害影响与未来之路(一)
这是本文的第1版,反映了截至2023年5月15日,Generative AI的已记载的和预期的危害。由于Generative AI的发展、使用和危害的快速变化,我们承认这是一篇内在的动态论文,未来会发生变化。 在本文中,我们使用一种标准格式…...
lightdb23.3 表名与包名不能重复
LightDB 表名与包名不能重复 从 LightDB 23.3 版本开始表名和包名不能重复,与 oracle 一致。原先已已支持包名和schema名不能重复。 背景 在之前版本在同一schema 下可以创建相同名字的表和包。这会导致在存储过程中使用%type指定变量类型时,如果存在…...
Oracle 开发篇+Java通过HiKariCP访问Oracle数据库
标签:HikariCP、数据库连接池、JDBC连接池、释义:HikariCP 是一个高性能的 JDBC 连接池组件,号称性能最好的后起之秀,是一个基于BoneCP做了不少的改进和优化的高性能JDBC连接池。 ★ Java代码 import java.sql.Connection; impor…...
进销存管理系统(小杨国贸)springboot采购仓库财务java jsp源代码mysql
本项目为前几天收费帮学妹做的一个项目,Java EE JSP项目,在工作环境中基本使用不到,但是很多学校把这个当作编程入门的项目来做,故分享出本项目供初学者参考。 一、项目描述 进销存管理系统(小杨国贸)spri…...
指针初阶(2)
文章目录 5. 指针和数组6. 二级指针7. 指针数组 附: 5. 指针和数组 指针变量:指针变量就是指针变量,不是数组,指针变量的大小是4/8个字节,专门是用来存放地址的。 数组:数组就是数组,不是指针&a…...
基于Gradio的GPT聊天程序
网上很多别人写的,要用账号也不放心。就自己写了一个基于gradio的聊天界面,部署后可以本地运行。 特点: 可以用openai的,也可以用api2d,其他api可以自己测试一下。使用了langchain的库 可以更改模型,会的…...
包管理工具详解npm 、 yarn 、 cnpm 、 npx 、 pnpm(2023)
1、包管理工具npm (1)包管理工具npm: Node Package Manager,也就是Node包管理器;但是目前已经不仅仅是Node包管理器了,在前端项目中我们也在使用它来管理依赖的包;比如vue、vue-router、vuex、…...
Terraform 系列-批量创建资源时如何根据某个字段判断是否创建
系列文章 Terraform 系列文章Grafana 系列文章 概述 前文 Grafana 系列 - Grafana Terraform Provider 基础 介绍了使用 Grafana Terraform Provider 创建 Datasource. 这几天碰到这么一个现实需求: 使用 Terraform 批量创建日志数据源时, 有的数据源类型是 El…...
Android侧滑栏(一)可缩放可一起移动的侧滑栏
在实际的各类App开发中,经常会需要做一个左侧的侧滑栏,类似于QQ这种。 今天这篇文章总结下自己在开发中遇到的这类可以跟随移动且可以缩放的侧滑栏。 一、实现原理 使用 HorizontalScrollView 实现一个水平方向的可滑动的View,左布局为侧滑…...
简单程度与自负是否相关?探索STM32的学习价值
事实上,无论STM32是否简单并不重要,更重要的是我们能通过学习STM32获得什么。通过STM32,我们可以学习到许多知识:如果我们制作一个键盘或鼠标,我们可以学习USB协议。如果我们制作一个联网设备,我们需要学习…...
第二章:CSS基础进阶-part3:弹性例子布局
文章目录 Flex盒模型二、常见属性2.1 flex属性2.2 justify-content2.3 flex-wrap2.4 flex-flow2.5 align-items2.6 父容器-align-content Flex盒模型 1、普通盒模型 2、弹性盒布局 使用弹性盒布局能让容器的宽度跟随浏览器窗口的变化而变换 二、常见属性 2.1 flex属性 2.2 …...
中南大学无人机智能体的全面评估!BEDI:用于评估无人机上具身智能体的综合性基准测试
作者:Mingning Guo, Mengwei Wu, Jiarun He, Shaoxian Li, Haifeng Li, Chao Tao单位:中南大学地球科学与信息物理学院论文标题:BEDI: A Comprehensive Benchmark for Evaluating Embodied Agents on UAVs论文链接:https://arxiv.…...
DAY 47
三、通道注意力 3.1 通道注意力的定义 # 新增:通道注意力模块(SE模块) class ChannelAttention(nn.Module):"""通道注意力模块(Squeeze-and-Excitation)"""def __init__(self, in_channels, reduction_rat…...
Nginx server_name 配置说明
Nginx 是一个高性能的反向代理和负载均衡服务器,其核心配置之一是 server 块中的 server_name 指令。server_name 决定了 Nginx 如何根据客户端请求的 Host 头匹配对应的虚拟主机(Virtual Host)。 1. 简介 Nginx 使用 server_name 指令来确定…...
return this;返回的是谁
一个审批系统的示例来演示责任链模式的实现。假设公司需要处理不同金额的采购申请,不同级别的经理有不同的审批权限: // 抽象处理者:审批者 abstract class Approver {protected Approver successor; // 下一个处理者// 设置下一个处理者pub…...
人机融合智能 | “人智交互”跨学科新领域
本文系统地提出基于“以人为中心AI(HCAI)”理念的人-人工智能交互(人智交互)这一跨学科新领域及框架,定义人智交互领域的理念、基本理论和关键问题、方法、开发流程和参与团队等,阐述提出人智交互新领域的意义。然后,提出人智交互研究的三种新范式取向以及它们的意义。最后,总结…...
Razor编程中@Html的方法使用大全
文章目录 1. 基础HTML辅助方法1.1 Html.ActionLink()1.2 Html.RouteLink()1.3 Html.Display() / Html.DisplayFor()1.4 Html.Editor() / Html.EditorFor()1.5 Html.Label() / Html.LabelFor()1.6 Html.TextBox() / Html.TextBoxFor() 2. 表单相关辅助方法2.1 Html.BeginForm() …...
给网站添加live2d看板娘
给网站添加live2d看板娘 参考文献: stevenjoezhang/live2d-widget: 把萌萌哒的看板娘抱回家 (ノ≧∇≦)ノ | Live2D widget for web platformEikanya/Live2d-model: Live2d model collectionzenghongtu/live2d-model-assets 前言 网站环境如下,文章也主…...
elementUI点击浏览table所选行数据查看文档
项目场景: table按照要求特定的数据变成按钮可以点击 解决方案: <el-table-columnprop"mlname"label"名称"align"center"width"180"><template slot-scope"scope"><el-buttonv-if&qu…...
数据结构:递归的种类(Types of Recursion)
目录 尾递归(Tail Recursion) 什么是 Loop(循环)? 复杂度分析 头递归(Head Recursion) 树形递归(Tree Recursion) 线性递归(Linear Recursion)…...
Django RBAC项目后端实战 - 03 DRF权限控制实现
项目背景 在上一篇文章中,我们完成了JWT认证系统的集成。本篇文章将实现基于Redis的RBAC权限控制系统,为系统提供细粒度的权限控制。 开发目标 实现基于Redis的权限缓存机制开发DRF权限控制类实现权限管理API配置权限白名单 前置配置 在开始开发权限…...
