1002. A+B for Polynomials (25)
来源:互联网 发布:windows ad与配置 编辑:程序博客网 时间:2024/05/16 19:40
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 Input2 1 2.4 0 3.22 2 1.5 1 0.5Sample Output
3 2 1.5 1 2.9 0 3.2
只通过了一个case,不知道为什么
x = [float(i) for i in raw_input().split(' ')]y = [float(i) for i in raw_input().split(' ')]z = [0,]i,j = 0,1ind = lambda x : 2 * x - 1coe = lambda x : 2 * xwhile i < x[0]: i += 1 if j > y[0] or x[ind(i)] > y[ind(j)]: z.append(x[ind(i)]) z.append(x[coe(i)]) continue else: while j <= y[0] and x[ind(i)] <= y[ind(j)]: if x[ind(i)] == y[ind(j)]: z.append(y[ind(j)]) z.append(x[coe(i)]+y[coe(j)]) else: z.append(y[ind(j)]) z.append(y[coe(j)]) j += 1z[0] = (len(z)-1)/2for i in z: print int(i) if round(i)==i else round(i,1),
0 0
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 【PAT】1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- PAT 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- [PAT]1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- pat 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- PAT 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- 1002. A+B for Polynomials (25)
- Remove Duplicates from Sorted Array II
- [LeetCode] Climbing Stairs
- 手动内存管理项目转ARC管理项目
- 阿里云ecs
- Linux-dd命令详解
- 1002. A+B for Polynomials (25)
- 20141218 N2
- php 获取时间今天明天昨天时间戳
- Spring测试框架JUnit4.4
- ORACLE PROCEDURE
- JAVA-day09-多线程
- 观察者(Observer) in Java
- java重构学习4:引入解释性变量(Introduce Explaing Variable)
- 用webBrowser打开网页出现脚本错误怎么办