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也有可能是负数,回头再看看)的更多相关文章

  1. pat 甲级 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. PAT甲级——1009 Product of Polynomials

    PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...

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

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

  5. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

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

  7. PAT甲级——A1009 Product of Polynomials

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

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

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

随机推荐

  1. virtualbox上,android x86 的分辨率的设置

    参考文章: http://stackoverflow.com/questions/6202342/switch-android-x86-screen-resolution 1) 用VBoxManage ...

  2. poj1459网络流之多源点最大流

    这题想了好久,一直认为应该bfs更新后求最小值把发电站最大发电加进去,但是又发现这样求增广路的时候会导致用户更新出错, 加源点和汇点也考虑到了,没想到居然发电量就是超级源到源点的v,居然这么简单@.@ ...

  3. UVA-4288 Cat vs. Dog (最大独立集)

    题目大意:猫狗大赛,s个猫和t个狗,有v个投票者,他们不是爱猫者就是爱狗者,所以爱猫者一定会对某条猫投晋级票,对某条狗投淘汰票,爱狗者亦然.现在已知这v个人的投票情况,应该使哪些畜牲晋级或淘汰才能使投 ...

  4. ps怎么替换颜色

    1.图像--->>调整--->>替换颜色

  5. 开源FTP软件FileZilla使用介绍

    简介 FileZilla是一个优秀的开源FTP软件,分为客户端版本和服务器版本,具备所有的FTP软件功能,如果想自己搭建FTP服务器,FileZilla是一个好选择. 下载 FileZilla有一个中 ...

  6. 征信接口调用,解析(xml)

    数据传输格式报文格式:xml public CisReportRoot queryCisReport(PyQueryBean pyQueryBean) throws Exception { CisRe ...

  7. java IO 学习(三)

    java IO 学习(一)给了java io 进行分类,这一章学习这些类的常用方法 一.File 1.创建一个新的File的实例: /** * 创建一个新的File实例 */ File f = new ...

  8. VMware上安装CenterOS

    1.环境:Win10.VMware Workstation 12.Centeros 7 2.VMware workstation12安装 双击“VMware_workstation_full_12.5 ...

  9. vim 编辑 windows下的文本时出现乱码, 修改配置后 已解决

    最近用VIM 查看一个 WINDOWS下的文本,打开以后发现出现乱码,具体如上图. 最后在网上找到了一个解决方法: 原文地址: https://www.zhihu.com/question/22363 ...

  10. c++ 读取所有图片

    copyright by Jun Yang, SUN YAT-SEN UNIVERSITY //FileList.h ///////////////////////////////////////// ...