问题描述:

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 N​1​​ a​N1​​​​ N​2​​ a​N2​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (,) are the exponents and coefficients, respectively. It is given that 1,0.

Output Specification:

For each test case you should output the sum 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 to 1 decimal place.

Sample Input:

2 1 2.4 0 3.2
2 2 1.5 1 0.5
 

Sample Output:

3 2 1.5 1 2.9 0 3.2

这题测试数据魔鬼!魔鬼!魔鬼!
同志们,作为多项式看待的时候,常数0不应该是算有1项且N1和aN1均为0吗?!我考虑了这种情况,结果有一个结果迟迟不对,哪料到把这个删了就对了,天理难容!
代码是同学发给我改的,所以比较丑。同学代码写的比较臃肿,缩进也挺不舒服的,凑合着看吧。我改的时候都没搞成tab缩进,现在自然也懒得弄了,反正AC了。

代码:
 #include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int atotal[];
int ktotal;
float btotal[]; void mix(int na,int a[],int nb,int b[],float c[],float d[])
{
int ia=,ib=;
while(ia<na&&ib<nb)
{
if (a[ia]>b[ib])
{
atotal[ktotal]=a[ia];
btotal[ktotal]=c[ia];
ia++;
}
else if (a[ia]<b[ib])
{
atotal[ktotal]=b[ib];
btotal[ktotal]=d[ib];
ib++;
}
else
{
atotal[ktotal]=a[ia];
btotal[ktotal]=c[ia]+d[ib];
ia++;ib++;
}
if (!(btotal[ktotal]>-0.05&&btotal[ktotal]<0.05)) ktotal++;
}
while(ia<na)
{
atotal[ktotal]=a[ia];
btotal[ktotal]=c[ia];
if (!(btotal[ktotal]>-0.05&&btotal[ktotal]<0.05)) ktotal++;
ia++;
}
while(ib<nb)
{
atotal[ktotal]=b[ib];
btotal[ktotal]=d[ib];
if (!(btotal[ktotal]>-0.05&&btotal[ktotal]<0.05)) ktotal++;
ib++;
}
} int main()
{
int k1,k2;
int a1[],a2[];
float b1[],b2[];
cin>>k1;
for (int i=;i<k1;i++){
cin>>a1[i];
cin>>b1[i];
}
cin>>k2;
for (int i=;i<k2;i++)
{
cin>>a2[i];
cin>>b2[i];
}
mix(k1,a1,k2,a2,b1,b2);
cout<<ktotal;
cout.precision ();
cout.setf(ios::fixed | ios::showpoint );
for (int i=;i<ktotal;i++){
cout << " " << atotal[i] << " " << round(*btotal[i])/10.0;
}
return ;
}

 
												

PTA 1002 A+B for Polynomials的更多相关文章

  1. PTA (Advanced Level) 1002 A+B for Polynomials

    1002 A+B for Polynomials This time, you are supposed to find A+B where A and B are two polynomials. ...

  2. 1002. A+B for Polynomials

    1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...

  3. PAT 1002. A+B for Polynomials (25) 简单模拟

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  4. PAT 甲级 1002 A+B for Polynomials (25 分)

    1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...

  5. PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  6. 1002 A+B for Polynomials (25)(25 point(s))

    problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...

  7. 【PAT】1002. A+B for Polynomials (25)

    1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...

  8. PAT甲级 1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  9. PAT 甲级1002 A+B for Polynomials (25)

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

随机推荐

  1. SpringBoot2.x操作缓存的新姿势

    一.介绍 spring cache 是spring3版本之后引入的一项技术,可以简化对于缓存层的操作,spring cache与springcloud stream类似,都是基于抽象层,可以任意切换其 ...

  2. 云服务器InfluxDB & Chronograf配置

    环境: 阿里云服务器 Ubuntu 18.04.3 LTS InfluxDB 1.7.10 (截至2020.2.20最新版) chonograf 1.8.0 (2020.2.19推出) 配置建议: 不 ...

  3. win10CPU版TensorFlow安装详细流程(踩N个坑之后的总结)

    版本说明: 多次实验后,python3.5+TensorFlow1.2+numpy1.16.4比较成功,不会报奇奇怪怪的错.(安装流程中会说到,不需要提前下载) 准备工作: 找到电脑:C:\Users ...

  4. spark 性能优化 数据倾斜 故障排除

    版本:V2.0 第一章       Spark 性能调优 1.1      常规性能调优 1.1.1   常规性能调优一:最优资源配置 Spark性能调优的第一步,就是为任务分配更多的资源,在一定范围 ...

  5. 终于成功部署 Kubernetes HPA 基于 QPS 进行自动伸缩

    昨天晚上通过压测验证了 HPA 部署成功了. 所使用的 HPA 配置文件如下: apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscale ...

  6. 大数相加-----杭电acm1002

    #include<stdio.h> #include<string.h> int main() { ], ch2[]; ], num2[]; ; scanf("%d& ...

  7. 注销Apache

    到D:\phpTools\Apache24\bin下运行cmd 输入httpd.exe -k uninstall -n apache24 回车后提示注销完成 接着把Apache的文件删了即可

  8. el-menu 菜单展示

    <template> <div class="tab-container"> <el-menu class="el-menu-vertica ...

  9. 一招教你用数据可视化BI软件创建网店运营监控大屏

    灯果数据可视化BI软件是新一代人工智能数据可视化大屏软件,内置丰富的大屏模板,可视化编辑操作,无需任何经验就可以创建属于你自己的大屏.大家可以在他们的官网下载软件. 本文以网店运营监控大屏为例为大家演 ...

  10. fancybox图片灯箱功能

    fancybox图片灯箱功能 在页面中引入几个文件 <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery ...