1009. Product of Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and 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

思路:多项式相乘,模拟即可,要注意的是最终结果中系数为0的项不需要输出。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define INF 0x3f3f3f
#define N_MAX 30+5
#define M_MAX 2001
struct x {
int exp;
double coef = ;
bool vis = ;
};
x poly1[N_MAX],poly2[N_MAX];
x poly[M_MAX];
int n1, n2;
int main() {
cin >> n1;
for (int i = ; i < n1; i++)cin >> poly1[i].exp >> poly1[i].coef;
cin >> n2;
for (int i = ; i < n2; i++)cin >> poly2[i].exp >> poly2[i].coef;
for (int i = ; i < n1;i++) {
for (int j = ; j < n2;j++) {
int exp = poly1[i].exp + poly2[j].exp;
poly[exp].vis = ;
poly[exp].exp= exp;
poly[exp].coef+= poly1[i].coef*poly2[j].coef;
}
} int num = ;
//系数为0的项不用输出!!!!!!!!!
for (int i = M_MAX-; i >= ; i--) if (poly[i].vis&&poly[i].coef!=) num++;
cout << num << " ";
for (int i = M_MAX-; i >=;i--) {
if (poly[i].vis&&poly[i].coef != ) {
num--;
printf("%d %.1f%c",poly[i].exp,poly[i].coef,num==?'\n':' ');
}
}
return ;
}

pat 甲级 1009. Product of Polynomials (25)的更多相关文章

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

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

  3. PAT甲级——1009 Product of Polynomials

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

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

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

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

  6. PATA 1009. Product of Polynomials (25)

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

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

  8. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

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

  9. 【PAT甲级】1009 Product of Polynomials (25 分)

    题意: 给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数. trick: 这道题数据未知,导致测试的时候发现不了问题所在. 用set统计非零项时,通过set.siz ...

随机推荐

  1. Pots POJ - 3414 (搜索+记录路径)

    Pots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22688   Accepted: 9626   Special J ...

  2. ElasticSearch High Level REST API【1】文档基本操作

    获取ES客户端 ES的提供了四种Java客户端,分别为节点客户端(node client).传输客户端(Transport Client).低级REST客户端.高级REST客户端. 节点客户端作为集群 ...

  3. Java 获取Web项目相对webapp地址

    例如, import java.io.File; import java.io.FileInputStream; import javax.servlet.http.HttpServletReques ...

  4. Centos7之Nginx

    1.安装 下载RPM: wget http://nginx.org/download/nginx-1.16.0.tar.gz 解压:tar -zxf nginx-1.16.0.tar.gz 安装: c ...

  5. 数据存储之使用mysql数据库存储数据

    推荐安装mysql5.7环境: 官网下载:https://dev.mysql.com/downloads/installer/5.7.html 如果提示没有.NET Framework框架.那么就在提 ...

  6. Union found

    Use array. class UnionFound { public: vector<int> v; int cnt; UnionFound(int n) { v = vector&l ...

  7. dfs 的全排列

    #include <iostream> #include <algorithm> #include <cstdio> #include <string> ...

  8. ZOJ Monthly, January 2018 训练部分解题报告

    A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...

  9. Session只读的影响

    .net中使用Session必须实现IRequiresSessionState接口,不过还有个只读的接口IReadOnlySessionState, 若是实现只读的接口,那么在该页面(如一般处理程序) ...

  10. xcode6没有prefix.pch预编译文件解决办法

    注意到Xcode6创建的工程没有prefix.pch. 于是手动创建. 在other下选择pch文件 接着到工程的build setting下设置开启预编译并配置路径(文件的路径.因为我新建在cofi ...