PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(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 a~N1~ N2 a~N2~ ... NK a~NK~, where K is the number of nonzero terms in the polynomial, Ni and a~Ni~ (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
算两个多项式polynomials的乘积,挺简单的一题,一开始就5分,原来c数组开太小,结果仍只有20分,原来a(未知数的次数)可能是负数,
乘积的未知数次数算出来是0的不要算进去
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
int k;
double num;
};
node a[];
node b[];
double c[];
int s=;
int main()
{
int n1;
while(cin>>n1)
{
s=;//记录最后有多少组
for(int i=;i<=n1;i++)
{
cin>>a[i].k>>a[i].num;
}
int n2;
cin>>n2;
for(int i=;i<=n2;i++)
{
cin>>b[i].k>>b[i].num;
}
memset(c,,sizeof(c));
for(int i=;i<=n1;i++)
{
for(int j=;j<=n2;j++)
{
int k=a[i].k+b[j].k;
if(k>&&c[k]==)
{
s++;
}
else if(k<&&c[-*k+]==)//万一是负数,特殊处理
{
s++;
k=-*k+;
}
c[k]+=a[i].num*b[j].num;
}
}
cout<<s;//输出组数
for(int i=;i>=;i--)
{
if(c[i]!=&&i>)
printf(" %d %.1f",-*(i-),c[i]);
else if(c[i]!=&&i<=)
printf(" %d %.1f",i,c[i]);
}
cout<<endl;
}
return ;
}
PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)的更多相关文章
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲级——1009 Product of Polynomials
PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...
- 1009 Product of Polynomials (25 分)
1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two pol ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
- 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 p ...
随机推荐
- P4 PI库安装
repo:Github PI P4Runtime - a control plane framework and tools for the P4 programming language 这个是P4 ...
- Ubuntu 14.04安装gnuplot 解决Terminal type set to 'unknown'问题 简易命令教程
参考: 照猫画虎学gnuplot之折线图 gnuplot 入门教程 1 gnuplot安装,及error:terminal type set to 'unknown'的解决 安装 sudo apt-g ...
- webpack执行中出现 ERROR in Path must be a string. Received undefined
执行webpack时出现错误信息 ERROR in Path must be a string. Received undefined 原因在于我的node.js版本太高了,目前node版本为6.10 ...
- django 常用字段类型
<> CharField #字符串字段, 用于较短的字符串. #CharField 要求必须有一个参数 maxlength, 用于从数据库层和Django校验层限制该字段所允许的最大字符数 ...
- Java中的基本数据类型及其封装类
Java中的数据类型有两种,基本数据类型和引用数据类型,引用数据类型的创建是 需要去new一个对象,该对象的内存分配在堆区,同时栈区会保存一个指向该对象的引用, 但是对于一些简单数据的创建,用new的 ...
- Git入门及常用命令(1)(window环境下)
文章参考摘抄自:git教程 1.git的安装 Windows下要使用很多Linux/Unix的工具时,需要Cygwin这样的模拟环境,Git也一样.Cygwin的安装和配置都比较复杂,就不建议你折腾了 ...
- 递归--练习3--noi7592求最大公约数问题
递归--练习3--noi7592求最大公约数问题 一.心得 两个低级错误:1. ll setMax(ll &m,ll &n)中无引用,结果只传值,没传地址2. return f(n,m ...
- Java研发工程师知识点总结
Java研发工程师知识点总结 最近一次更新2017年12月08日 大纲 一.Java基础(语言.集合框架.OOP.设计模式等) 二.Java高级(JavaEE.框架.服务器.工具等) 三.多线程和并发 ...
- 使用springfox+swagger2书写API文档(十八)
使用springfox+swagger2书写API文档 springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API,swagger主要用于展示springfo ...
- 018PHP基础知识——函数(一)
<?php /** *函数:一部分可重复执行的代码段,多次执行一次编译 * 特点: * 1.减少程序运行的复杂性 * 2.提高程序的可靠性 * 3.提高软件的开发效率 * 4.提高程序的维护性 ...