PTA A1009&A1010

第五天

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了

原文地址:https://www.cnblogs.com/z-y-k/p/11538045.html

时间: 2024-08-30 08:15:01

PTA A1009&A1010的相关文章

ERROR&lt;53761&gt; - 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-Directory/6.3 B2008.0311.0224 (32-bit) starting up[04/May/2016:21:10:39 +0800] - Listening on all interfaces port 11111 for LDAP requests[04/May/2016:21:10

PTA 5-8(English) File Transfer (25) - 并查集 - 数组实现

题目:http://pta.patest.cn/pta/test/16/exam/4/question/670 PTA - Data Structures and Algorithms (English) - 5-8 We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer t

PTA Huffman Codes

题目重现 In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in the history of computer science. As a professor who gives the final exam problem on Huffman codes, I am

PTA 10-排序6 Sort with Swap(0, i) (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/678 5-16 Sort with Swap(0, i)   (25分) Given any permutation of the numbers {0, 1, 2,..., N-1N?1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is

PTA 10-排序4 统计工龄 (20分)

题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/721 5-13 统计工龄   (20分) 给定公司NN名员工的工龄,要求按工龄增序输出每个工龄段有多少员工. 输入格式: 输入首先给出正整数NN(\le 10^5≤10?5??),即员工总人数:随后给出NN个整数,即每个员工的工龄,范围在[0, 50]. 输出格式: 按工龄的递增顺序输出每个工龄的员工个数,格式为:"工龄:人数".每项占一行.如果人数为0则不输出该项. 输入样

PTA 09-排序2 Insert or Merge (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/675 5-13 Insert or Merge   (25分) According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort rem

PTA 10-排序5 PAT Judge (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge   (25分) The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT. Input Spe

PTA 09-排序1 排序 (25分)

题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/720 5-12 排序   (25分) 给定NN个(长整型范围内的)整数,要求输出从小到大排序后的结果. 本题旨在测试各种不同的排序算法在各种数据情况下的表现.各组测试数据特点如下: 数据1:只有1个元素: 数据2:11个不相同的整数,测试基本正确性: 数据3:103个随机整数: 数据4:104个随机整数: 数据5:105个随机整数: 数据6:105个顺序整数: 数据7:105个逆序整数

PTA 09-排序3 Insertion or Heap Sort (25分)

题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/676 5-14 Insertion or Heap Sort   (25分) According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion s