1002. A+B for Polynomials (25) (浮点数判0)
This time, you are supposed to find A+B where A and B are two polynomials.
Input
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, 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
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
这题翻译过来其实就是多项式加法
#include<stdio.h>
#include<stdlib.h>
#include<math.h> int main()
{
int n;
int i,j;
double xi;
int zi;
double a[];
int cnt=; for( i=;i<; i++)
{
a[i] = ;
}
for( i=; i<; i++){
scanf("%d",&n);
for( j=; j<n; j++){
scanf("%d %lf",&zi,&xi);
a[zi] += xi;
}
} for( i=; i>=; i--){
if( fabs(a[i])>1e-)
cnt++;
}
printf("%d",cnt);
for( i=; i>=; i--){
if( fabs(a[i])>1e-)
printf(" %d %.1lf",i,a[i]);
} return ;
}
1002. A+B for Polynomials (25) (浮点数判0)的更多相关文章
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- PAT 甲级1002 A+B for Polynomials (25)
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
- 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 ...
- 【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 ...
- 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 ...
- 1002. A+B for Polynomials (25)
题目链接:https://www.patest.cn/contests/pat-a-practise/1002 原题如下: This time, you are supposed to find A+ ...
- PAT Advanced 1002 A+B for Polynomials (25 分)(隐藏条件,多项式的系数不能为0)
This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...
随机推荐
- Codeforces Round #459 (Div. 2)C. The Monster
C. The Monster time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Tree POJ - 174
点分模板题 都快改的跟题解一模一样了2333333 #include<cstdio> #include<cstring> #include<algorithm> u ...
- The Fewest Coins POJ - 3260
The Fewest Coins POJ - 3260 完全背包+多重背包.基本思路是先通过背包分开求出"付出"指定数量钱和"找"指定数量钱时用的硬币数量最小值 ...
- LinkedList,SortedList 基本用法
LinkedList类是双向列表,列表中的每个节点都包含了对前一个和后一个元素的引用. LinkedList<int> ma = new LinkedList<int>(); ...
- C#中的预编译指令介绍[转]
原文链接 1.#define和#undef 用法: #define DEBUG #undef DEBUG #define告诉编译器,我定义了一个DEBUG的一个符号,他类似一个变量,但是它没有具体的值 ...
- Uncaught TypeError: Cannot set property 'f7View' of undefined 错误原因
// 添加视图var mainView = myApp.addView('.view-main', { // 因为我们要用动态的导航栏,我们需要使它的这一观点: dynamicNavbar: true ...
- android开发学习——Socket发送和接收
client -- server发送过程中,涉及的输入流输出流: http://blog.csdn.net/dlwh_123/article/details/35982015 (良心好文) 需 ...
- node入门(二)——gulpfile.js初探
本文关于gulpfile.js怎么写,利于完成个性化需求.本文开发环境默认已安装node,详情参考<node入门(一)——安装>. 一.安装gulp npm install -g gulp ...
- 不支持正在使用的 .Net 组帧模式。有关详细信息,请参阅服务器日志--解决方案
问题在于 NetTcpBinding 服务端和客户端配置不一致. 至少 客户端和服务端:安全性.是否启用可靠会话以及传输方式必须一致 主要是传输方式导致 "不支持正在使用的 .Net 组帧 ...
- Android基础夯实--重温动画(三)之初识Property Animation
每个人都有一定的理想,这种理想决定着他的努力和判断的方向.就在这个意义上,我从来不把安逸和快乐看作生活目的的本身--这种伦理基础,我叫它猪栏的理想.--爱因斯坦 一.摘要 Property Anima ...