问题描述:

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. javascript canvas全部API

    HTMLCanvasElement//canvas elem对象 属性 height//高 width//宽 方法 getContext()//获取<canvas>相关的可绘制的上下文 t ...

  2. 浅谈无线局域网WLAN

    无线局域网WLAN 一.概述 有线局域网的组成如下图所示,多台计算机通过双绞线连接到一个集线器(hub)或交换机(switch)上,组成一个有限局域网. 无线局域网的组成如下图所示,多台计算机通过无线 ...

  3. C标准库与嵌入式

    stddef.h,其中包括size_t,sizeof函数返回值,不同平台的大小不一致 Size and pointer difference types[edit] The C language sp ...

  4. 外网访问oracle 很慢

    一台oracle服务器  对外网开放服务,外网连接后查询速度很慢,内网查询非常快.应该是这个cisco的防火墙有问题,查了很久 没有找到原因. 临时解决方法,在内网再建一台 跳转服务器,外网查询数据库 ...

  5. Linux 发行版本简述

            在撰写这篇文章前,先向linux创始人 Linus Torvalds 先生致敬,感谢您二十多年前的无私开源!         其次向二十多年来维护更新的开发者们致敬!      Lin ...

  6. nginx官网版本说明

    nginx软件下载:http://nginx.org/en/download.html Mainline version:Nginx 正在主力开发的版本Stable version:最新稳定版,生产环 ...

  7. 国内jenkins搭建不再龟速的方式

    最新国内jenkisn搭建过程 第一步下载jenkins 点击进入清华源jenkins下载地址,我们下载的是jenkins-2.204.2.zip版本 之后解压后安装. 第二步配置管理员密码 自动弹出 ...

  8. Ubuntu 18.04 MATLAB 安装及配置

    转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12367846.html 本文要点: Ubuntu 18.04 安装 ...

  9. RedHat7安装NetCore环境并发布网站

    RedHat7安装NetCore环境并发布网站 1.注册Microsoft签名密钥并添加Microsoft产品提要,每台机器只需注册一次 执行下面的命令即可 rpm -Uvh https://pack ...

  10. Mysql数据库操作(命令行)

    1 环境 树莓派: mysql: 2  指令 以下是从命令行中连接mysql服务器的简单实例: [root@host]# mysql -u root -p Enter password:****** ...