问题描述:

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. 怎么理解Laravel的核心架构

    使用过larave框架的朋友都知道laravel框架里面除了提供一些基本的功能(如控制器.视图.模型)之外,还有中间件.门面.契约等,这些东西是如何在laravel框架运用起来的呢?今天就和大家详聊一 ...

  2. vue的组件传值

    1.父组件向子组件传值 父组件: 123456789101112 <template> <child :name="name"></child> ...

  3. mount.nfs: Stale file handle的解决方法

    在NFS客户端挂载rpc共享服务的时候出现这个问题 # mount -t nfs 192.168.20.6:/data /mnt mount.nfs: Stale file handle 原因是当cl ...

  4. 数据算法 --hadoop/spark数据处理技巧 --(7.共同好友 8. 使用MR实现推荐引擎)

    七,共同好友. 在所有用户对中找出“共同好友”. eg: a    b,c,d,g b    a,c,d,e map()->  <a,b>,<b,c,d,g> ;< ...

  5. (转载)Linux平台下安装 python 模块包

    https://blog.csdn.net/aiwangtingyun/article/details/79121145 一.安装Python Windows平台下: 进入Python官网下载页面下载 ...

  6. 基于已构建S2SH项目配置全注解方式简化配置文件

    如果还不熟悉s2sh项目搭建的朋友可以先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 eclipse环境下基于已构建struts2项目整合spring+hiberna ...

  7. jps jmap 的使用

    第一部分: 源代码: public class ObjectText { int a=0; public static void main(String[] args) { ObjectText ot ...

  8. 1、Docker部署及基础理论

    1.Docker入门简介 Docker技术类似码头上看到的集装箱,最早集装箱没有出现的时候,码头上有许多搬运的工人在搬运货物,有了集装箱以后,搬运货物变得简单,通过集装箱的搬运模式更加单一.高效,将货 ...

  9. appium+python+unittest+HTMLRunner登录自动化测试报告

    环境搭建 python3Java JDK.netFrameworknodejsandroid SDKappiumAppium-Python-Client(pip install Appium-Pyth ...

  10. Excel开启宏以后保存是会提示安全警告,怎么取消

    如果你用的(应该)是2007以上版本的话 请点左上角的EXCEL图标,EXCEL选项,信任中心,信任中心设置,个人信息选项,保存时从文件属性中删除个人信息前面的对号取消.确定就可以了. (补充:如果你 ...