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 ...
随机推荐
- Linux 下源码编译安装 vim 8.1
前言 目前 linux 的各个发行版基本上都是带了一个 vi 编辑器的,而本文要说的 vim 编辑器对 vi 做了一些优化升级,更好用.当我们需要远程操作一台 linux 服务器的时候,只能使用命令行 ...
- BloomFilter–大规模数据处理利器
转自: http://www.dbafree.net/?p=36 BloomFilter–大规模数据处理利器 Bloom Filter是由Bloom在1970年提出的一种多哈希函数映射的快速查找算法. ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- "CMAKE_CXX_COMPILER-NOTFOUND"
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CM ...
- Spark读取结构化数据
读取结构化数据 Spark可以从本地CSV,HDFS以及Hive读取结构化数据,直接解析为DataFrame,进行后续分析. 读取本地CSV 需要指定一些选项,比如留header,比如指定delimi ...
- nodejs使用multiparty模块实现文件上传(另附express.bodyParser()的说明)
最近师弟师妹们在用formidable做文件上传的时候会出现form.parse()不会触发的问题,在stackoverflow也没有找到答案,反而是几个答案推荐使用multiparty来代替,因为那 ...
- 045——VUE中组件之父组件使用scope定义子组件模板结构
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SGU 131. Hardwood floor 状压dp 难度:2
131. Hardwood floor time limit per test: 0.25 sec. memory limit per test: 4096 KB The banquet hall o ...
- android adapter的性能小结
一般adapter的做法会重写getView方法 比如 @Override public View getView(int position, View convertView, ViewGroup ...
- web service与EJB的区别
1.WebService可以说是跨平台的,因为它采用的是XML技术,说穿了就是把你的请求按照该WebServece的标准将参数传过去,然后服务器返回结果,当然了最重要的是参数的传递和结果的返回都是采用 ...