1009 Product of Polynomials (25 point(s))

PAT-A1002 A+B for Polynomials 题目内容及题解 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 informa... 阅读详情

1009 Product of Polynomials (25 point(s))

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 N​1​​ a​N​1​​​​ N​2​​ a​N​2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N​K​​<⋯<N​2​​<N​1​​≤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

 

#include<iostream>
using namespace std;
const int A_MAX = 1007;
const int R_MAX = 2007;
int main(void){
	int N,M,exp;
	double coe;
	double a[A_MAX]={0};
	double res[R_MAX]={0};
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d%lf",&exp,&coe);
		a[exp]+=coe;
	}
	scanf("%d",&M);
	for(int i=0;i<M;i++){
		scanf("%d%lf",&exp,&coe);
		for(int i=0;i<A_MAX;i++){
			if(a[i]!=0){
				res[i+exp]+=a[i]*coe;
			}
		}
	}
	int r=0;
	for(int i=0;i<R_MAX;i++){
		if(res[i]!=0) {
			r++;
		}
	}
	printf("%d",r);
	for(int i=R_MAX-1;i>=0;i--){
		if(res[i]!=0){
			printf(" %d %.1f",i,res[i]);
		}
	}
	printf("\n");
	return 0;
}

https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344

PAT甲级真题 1009 Product of Polynomials (25分) C++实现(使用map,注意测试点0的坑) 题目 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 infor... 阅读详情

相关推荐

【MCU】一种基于RTOS的无应答重发机制

文章目录一、背景描述二、结构框图三、基于RTOS的信号量的实现(3-1)思路描述(3-2)步骤(3-2-1)定义超时重发信号量(3-2-2)定义发送线程入口(3-2-3)定义接收线程入口四、基于定时器的实现(4-1)思路描述(4-2)步骤(4-2-1)创建定时器(4-2-2)定义定时器超时处理函数(4-2-3)定义发送线程入口(4-2-4)定义接收线程入口 一、背景描述 ​ 在微控制器之间进行数据通信时,大多需要添加无应答重发机制,以增强数据交互和通信的稳定性。 在使用UART通信的双方设备,当一次数据传输

iriczhao的博客 1523

【PAT刷题甲级】1009.Product of Polynomials

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

C_greenbird的博客 399

基于多智能体协作的量化交易研究框架TradingAgents详解

量化交易系统通过算法模型分析市场数据,旨在实现自动化投资决策。其核心原理在于利用计算机强大的数据处理能力,结合统计学和机器学习方法,从历史数据中挖掘可重复的盈利模式。这一技术的价值在于能够克服人类情绪干扰,实现纪律性交易,并快速处理海量信息。在应用场景上,量化策略广泛应用于股票、期货、外汇等多个金融市场。本文聚焦的TradingAgents框架,创新性地引入了**多智能体协作**和**对抗性验证**机制,通过模拟真实投研团队的分工与辩论流程,构建了一个研究友好、决策过程可解释的量化交易研究平台,为探索大语言

weixin_36019375的博客 433

1009 Product of Polynomials 详解

目录 题目 输入样例1(题目自带) 输出样例1 输入样例2(自编,特殊情况) 输出样例2 提交结果截图 解题思路及源代码 题目 题目链接:1009 Product of Polynomials(PAT (Advanced Level) Practice) 输入样例1(题目自带) 2 1 2.4 0 3.2 2 2 1.5 1 0.5 输出样例1 3 3 3.6 2 6.0 1 1.6 输入样例2(自编,特殊情况) 0 1 3 3.6 输出样例2 0 提交结果.

NOT_TODAY1的博客 1101

NRF24L01学习操作教程(二)——NRF实现一对一,一对多通讯

以上内容详细介绍了,使用NRF24L01实现1对1单向通讯、1对1双向通讯、1对多双向通讯。

Joseph Wen的博客 7389

UOS的ARM机编译QT5.14.2记录

我需要的qt版本是Qt5.14.2,所以选择编译Qt5.14.2源码;几个月前尝试了编译一次,当时编译过程中出现了报错,当时时间很紧最后安装的默认版本来使用,最近有时间重新进行了一次编译,历经3个星期(4G的内存)终于解决了各种坑,编译成功了,现在将编译过程中遇见的一些坑记录一下,方便日后能记得这一次可恶的编译过程,如有描述欠缺的地方,还希望各位大佬给点意见指导指导🙏。

NiF693zzz的博客 1619

1002. A+B for Polynomials (25)-PAT甲级真题

This time, you are supposed to find A+B where A and B are two polynomials. InputEach input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynom...

柳婼 の blog 5333

小程序强制更新避坑指南:手把手教你实现无缝升级

本文详细解析小程序强制更新的实现方法,重点介绍wx.getUpdateManager API的使用技巧,帮助开发者规避冷热启动机制下的版本管理陷阱。通过实战案例展示如何设计多级更新提示策略,确保用户无缝升级,提升小程序版本更新率。

star的博客 281

PTA 甲级 1002 A+B for 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 informati...

ice123muxin的博客 674

基于MATLAB实现语音信号MFCC特征提取(附完整代码)

你有没有想过你的智能手机是如何理解语音指令的?或者 Alexa 和 Siri 等语音助手如何处理您的命令?这种卓越能力背后的机制在很大程度上归功于一种称为 Mel 频率倒谱系数 (MFCC) 的方法。语音识别技术允许机器解释人类语音,将口语转换为计算机可以操纵的格式。这项技术对于开发交互式和响应式 AI 至关重要,例如声控助手、自动化客户服务系统和实时翻译服务。MFCC 代表 Mel 频率倒谱系数。这是用于自动语音和说话人识别的功能。

baidu_34971492的博客 1314

验证码破解2.0:Python+CV大模型搞定滑块/点选验证

核心创新:基于YOLOv8+SAM CV大模型的端到端验证码破解方案,无需人工设计特征,适配多种验证码类型;核心价值高成功率:滑块验证≥95%,点选验证≥90%,远超传统CV方案;低延迟:单验证码破解≤2秒,满足高并发采集需求;行为模拟:生成符合人类操作的轨迹,绕过行为检测;易扩展:统一架构支持新增验证码类型,仅需少量标注数据微调;技术要点采用YOLOv8实现快速目标检测,SAM实现像素级分割;生成物理规律的人类轨迹,模拟真实操作行为;

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1261

1009 Product of Polynomials (25 point(s))

题解 同1002类似。  #include&lt;iostream&gt; #include&lt;cstdio&gt; using namespace std; const int MAXN = 1000010; const int MAXM = 1001; #define EPS 1e-6 float result[MAXN], ans[MAXM]; int cnt, k, n; f...

徐伯莱 240

Unity零基础到进阶 | Unity 探针系统深度解析:光照探针、反射探针与相关技术

在 Unity 渲染管线中,探针(Probe) 是一类通过预计算或实时采样来捕捉空间光照信息的核心组件。它们弥补了传统静态光照贴图和实时光源各自的局限性,是实现高质量、高性能全局光照效果的关键工具。 本文将系统介绍光照探针(Light Probe)和反射探针(Reflection Probe)的作用与用法,分析二者之间的协同关系,并延伸介绍自适应探针体积(APV)、光照探针代理体(LPPV)、探针体积等进阶技术。

努力前行,总会成为自己心中的那道光 1万+

1009 Product of Polynomials (25point(s))

1009 Product of Polynomials (25point(s)) 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 polynom

佳迪斯的博客 172

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

1009 Product of Polynomials (25 point(s)) - C语言 PAT 甲级

设计思路: * 利用数组下标表示指数,数组本身存取对应系数

有三只土豆 224

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

1009 Product of Polynomials (25 point(s))

1009 Product of Polynomials (25 point(s)) 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 polyno

utopianist的博客 285

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

PAT(甲级)1009 Product of Polynomials (25point(s))

题目 题目链接 思路 题目大意:求多项式的乘积; 先把第一个多项式保存下来,读入第二个多项式的每一项时与第一项的每个非零项做乘积,用另一个数组保存; 注意,最后这个数组的大小至少为2001,因为两个1000多项式相乘会达到2000; 代码 #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; const int max

hjyp的博客 218

1009 Product of Polynomials (25)(25 point(s))

problem 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...

weixin_30702413的博客 126

PTA甲1009 Product of Polynomials (25 point(s))

This time, you are supposed to findA×BwhereAandBare 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: KN​1​​a​N​1​​​​N​2​​a​N​2​​​​...

qq_46626443的博客 145

PAT (Advanced Level) Practice 1009 Product of Polynomials (25 point(s))

题目:PAT A 1009 题目大意 两个多项式A,B。求两个多项式的乘积。 解题思路 设立一个2000的数组,表示次方,剩余就是模拟的过程。 #include<bits/stdc++.h> using namespace std; const int maxn=2e3+5; double poly[maxn]; double poly2[maxn]; int main(){ int k1,k2; scanf("%d",&k1); int a; dou

helloful的博客 219

PAT(A) 1009 Product of Polynomials (25 point(s)) C++ 测试点0

注意:系数相加为零的要舍去,否则Case 0:Wrong Answer #include<cstdio> #include<map> using namespace std; int main(void){ int K, N; float a; map<int, float> p1, p2, m; scanf("%d", &K); for(int i = 0; i < K; i++){scanf("%d %

Anpotan的博客 233

PTA 甲级 1009 Product of Polynomials (25 分) 多项式相乘

题目 题意简单,两个多项式相乘。 每一个多项式K是项数,接着是K个指数,常数。 This time, you are supposed to findA×BwhereAandBare two polynomials. Input Specification: Each input file contains one test case. Each case occupies ...

117瓶果粒橙 360

A1009 Product of Polynomials (25 分| 简单模拟,附详细注释,逻辑分析)

写在前面 思路分析 简单模拟 double类型的arr数组保存第1组数据, ans数组保存结果 指数作为下标 当输入第2组数据的时候,边运算边保存结果 最后按照指数递减顺序输出所有不为0的项 问题点 相乘后指数可能最大为2000,所以ans数组最大要开到2001 题目简单,细节处理耗费时间 测试用例 input: 2 1 2.4 0 3.2 2 2 1.5 1 0.5 o...

kngines 270
上一篇: 1008 Elevator (20 point(s))
下一篇: 1007 Maximum Subsequence Sum (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值