第五天

A1009 Product of Polynomials (25 分)

题目内容

This time, you are supposed to find A×B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

K N1 aN1 N2 aN2... NKaNK

where K is the number of nonzero terms in the polynomial, Niand aNi(i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10,0≤NK<⋯<N2<N1≤1000.

Output Specification:

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

Sample Input:

2 1 2.4 0 3.2

2 2 1.5 1 0.5

Sample Output:

3 3 3.6 2 6.0 1 1.6

单词

product

英 /'prɒdʌkt/ 美 /'prɑdʌkt/

n. 产品;结果;[数] 乘积;作品

题目分析

多项式相乘,类似于A1002的多项式相加,之前也写过用的开结构体数组的方法,很笨,所以用之前在A1002学到的开一个数组,用下标代表指数,对应元素代表系数的方式来存,不过因为是乘法所以要多开两个数组把数据临时保存一下。代码如下。

具体代码

#include<stdio.h>
#include<stdlib.h> double p1[1001];
double p2[1001];
double res[2002];
int N, M;
int main(void)
{
scanf("%d", &N);
for (int i = 0; i = 0; i--)
{
if (res[i] != 0)
printf(" %d %0.1f", i, res[i]);
}
system("pause");
}

A1010 Radix (25 分)

题目内容

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 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:

6 110 1 10

Sample Output:

2

单词

radix

英 /'rædɪks; 'reɪ-/ 美 /'redɪks/

n. 根;[数] 基数

n. (Radix)人名;(法、德、西)拉迪克斯;(英)雷迪克斯

decimal

英 /'desɪm(ə)l/ 美 /'dɛsɪml/

n. 小数

adj. 小数的;十进位的

题目分析

从9点做到11点多,巨坑,第一次是默认最大基数为36,部分通过,找不到bug很懵,上网查了一会儿看了一些博客才知道,最大的基数不一定是36,可以非常的大,最大值应该是已经算出的值+1,由于数据可以非常的大,所以int的数据大小肯定是不够了,而且用暴力方法遍历查找,必然会超时,这时候就要用二分查找,于是把之前写的全删掉重新写了个二分查找的代码,调试完依然有几个无法通过,于是把自己的代码和别人已经AC的代码对比,发现大佬的代码中在二叉搜索时多了一个判断条件,即算出的值需要判断是否小于0,这是因为如果数字实在太大甚至超过了long long的范围,那么这时我们去另一半继续找基数,我对这里有一点疑惑,如果数据真的特别大,或者基数卡在溢出和mid中间,那么这个方法可能找不到,可是数据又是无限的,所以这个问题深究起来可能是无解的(这么看来这好像是个数学问题,不知道有没有大佬能证明出来这道题到底有没有通解)。最后的最后,大家在开字符数组的时候一定记得要加一。。。。。

对了,关于把字符串转换成数字的问题,我之前一直用的是算出数组长度,减一后用math.h里的pow算出每个进位的值后一个一个加,今天看了大佬的代码,发现了一种更简洁的方法:

int sum=0;
while(\*p != '\0')
{
int n = convert(\*p);
sum = sum \* radix + n;
p++;
}

具体代码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSIZE 11

char s1[MAXSIZE];
char s2[MAXSIZE];
int tag;
long long radix;
long long result;
long long int finalradix;

int convert(char a)
{
if (a >= '0'&&a max)
max = f;
p++;
}
return max + 1;
}

long long binary_search(long long result,char *s,long long rmin,long long rmax)
{
while (rmin result || n

参考博客

【笨方法学PAT】1010 Radix(25 分)

1010 Radix (25 分)

*甲级PAT 1010 Radix(二分搜索+坑)

1010 Radix (25 分)C++实现-终于AC了

PTA A1009&A1010的更多相关文章

  1. 浙大PTA - - 堆中的路径

    题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...

  2. 浙大PTA - - File Transfer

    题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...

  3. ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...

    LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...

  4. PTA中提交Java程序的一些套路

    201708新版改版说明 PTA与2017年8月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...

  5. PTA分享码-Java

    主要用于Java语法练习,非竞赛类题目.   1. Java入门          959dbf0b7729daa61d379ec95fb8ddb0   2. Java基本语法   23bd8870e ...

  6. C语言第一次实验报告————PTA实验1.2.3内容

    一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...

  7. PTA题---求两个有序序列中位数所体现的思想。

    ---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数.有序序列A​0​​,A​1​​, ...

  8. 第十四,十五周PTA作业

    1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...

  9. 第七周PTA作业

    第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...

随机推荐

  1. 弹性布局(display:flex;)属性详解

    Flexbox 是 flexible box 的简称(注:意思是“灵活的盒子容器”),是 CSS3 引入的新的布局模式.它决定了元素如何在页面上排列,使它们能在不同的屏幕尺寸和设备下可预测地展现出来. ...

  2. HBase 系列(六)——HBase Java API 的基本使用

    一.简述 截至到目前 (2019.04),HBase 有两个主要的版本,分别是 1.x 和 2.x ,两个版本的 Java API 有所不同,1.x 中某些方法在 2.x 中被标识为 @depreca ...

  3. vim文件时,误用了ctrl+z命令,该怎么办?

    linux中,当正在使用vim命令编辑文件,退出时,如果误使用了 ctrl+z ,当前目录中会多一个隐藏文件. 比如我正在编辑 t.txt 文件时,误以为我之前使用的是 tail 命令,直接使用 ct ...

  4. 史上最全面的SignalR系列教程-6、SignalR 实现聊天室

    1.概述 通过前面几篇文章对SignalR的详细介绍.我们知道Asp.net SignalR是微软为实现实时通信的一个类库.一般情况下,SignalR会使用JavaScript的长轮询(long po ...

  5. 9043Markdown常用用法

    1.标题 1.1 方法一:==和--标记 =和-标记语法格式如下: 我是标题一 == 我是标题二 -- 组成: 1标题文字:我是标题一 2回车换行 3标记:== (为一级标题)--(为二级标题) 效果 ...

  6. 【阿里云IoT+YF3300】4.Alink物模型之事件触发

    名词解释:设备的功能模型之一,设备运行时的事件,事件一般包含需要被外部感知和处理的通知信息,可包含多个输出参数.如,某项任务完成的信息,或者设备发生故障或告警时的温度等,事件可以被订阅和推送. 在工控 ...

  7. 学测试,看视频?NONONO,除非这种情况

    001 前言 : 很久没周末写文章了,一个是要睡懒觉.另外一个是,周末写了大家也没有心思看(加班1周了,好不容易周末,你又让我学习 ?先睡个懒觉再说,去TM的学习). 然而,今天早早的5点就起床了,处 ...

  8. [Python] 数据结构--实现顺序表、链表、栈和队列

    说明: 本文主要展示Python实现的几种常用数据结构:顺序表.链表.栈和队列. 附有实现代码. 来源主要参考网络文章. 一.顺序表 1.顺序表的结构 一个顺序表的完整信息包括两部分,一部分是表中元素 ...

  9. 从零开始搭建Java开发环境第二篇:如何在windows10里安装MySQL

    1 下载安装包 1.1 压缩包 https://dev.mysql.com/downloads/mysql/ [外链图片转存失败(img-oesO8K09-1566652568838)(data:im ...

  10. 用故事解析setTimeout和setInterval(内含js单线程和任务队列)

    区别: setTimeout(fn,t): 延迟调用,超过了时间就调用回调函数,返回一个id,使用clearTimeout(id)取消执行. 注意:取消了里面的回调函数就不执行了哦,而不是取消的时候就 ...