我在对数据处理的时候,没有考虑负数加和,因此测试点 0 过不去。 所以在39行代码下方加入以下判断:if (Result[i->first + j->first] == 0) Result.erase(i->first + j->first); 即可满分通过 完整代码如下:#include<iostream> #include<string> #include<stdio.h> #include using namespace std; stru...
where K is the number of nonzero terms in thepolynomial, 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 ofAa...
vector<int> p_n;boolcmp(inta,intb){//从大到小returna>b; }intmain(){// freopen("data.txt","r",stdin);fill(p,p+N,0);intn,m;doublea; map<int,double> pa;scanf("%d",&m);for(inti =0;i<m;i++){scanf("%d %lf",&n,&a);if(a!=0) pa.insert(make_pair(n,a)); }sc...
1009 Product of Polynomials 折腾半天ac不了,试了图中的例子,非零项计数出错,还以为是浮点数比较出了问题,想fabs()再与const float ZERO=1e-6比较判断是否为0 然鹅。。。 partially accected的主要原因是,只考虑了原先这个幂次的系数是不是0,没有在运算后在判断一下是否为0。 Screen Shot 2019-01-23 at...
首先,输出要按照指数递减顺序,也就是按照数学中的习惯,那么这个地方就需要一个排序,其次要输出非零项个数再输出非零项,这一点我自己刚开始也没有注意到,导...1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: ...
PAT 1009 Product of Polynomials PAT 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...【PAT】1009 Product of Polynomials ......
1009 Product of Polynomials (25分) This time, you are supposed to findA×B whereA andB 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 .....
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 beNOextra space at the end of each line. Please be accurate up to 1 decimal place. Sample Input: ...
for(int i=max_n-1;i>=0;i--){ if(h[i]!=0){ printf(" %d %.1f",i,h[i]); } } return 0; } 方法二代码: 还有一种用结构体的写法: #include<cstdio> #include<algorithm> struct Poly{ int exp; //指数 double cof; //系数 ...
This time, you are supposed to findA×BwhereAandBare twopolynomials. Input Specification: Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: whereKis the number of nonzero terms in the polynomial,Ni andaNi ...