1002. A+B for Polynomials

1002. A+B for Polynomials (25)

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5
 6 int main()
 7 {
 8     double a[1010], b[1010];
 9     memset(a, 0, sizeof(a));
10     memset(b, 0, sizeof(b));
11     int ka, kb, i, j, x, y, maxa, maxb;
12     scanf("%d", &ka);
13     scanf("%d", &x);
14     scanf("%lf", &a[x]);
15     maxa = x;
16     for(i = 1; i < ka; i++)
17     {
18         scanf("%d", &x);
19         scanf("%lf", &a[x]);
20     }
21     scanf("%d", &kb);
22     scanf("%d", &y);
23     scanf("%lf", &b[y]);
24     maxb = y;
25     for(i = 1; i < kb; i++)
26     {
27         scanf("%d", &y);
28         scanf("%lf", &b[y]);
29     }
30     if(maxa < maxb)
31     {
32         int temp = maxa;
33         maxa = maxb;
34         maxb = temp;
35     }
36     for(i = maxa; i >= 0; i--)
37     {
38         a[i] += b[i];
39     }
40     int count = 0;
41     for(i = maxa; i >= 0; i--)
42     {
43         if(a[i] != 0)
44             count++;
45     }
46     printf("%d", count);
47     for(i = maxa; i >= 0; i--)
48     {
49         if(a[i] != 0)
50         {
51             printf(" %d %.1f", i, a[i]);
52         }
53     }
54     printf("\n");
55     return 0;
56 }
时间: 2024-10-11 03:29:25

1002. A+B for Polynomials的相关文章

1002. A+B for Polynomials (25)

题目: 1002. A+B for Polynomials (25) #include<stdio.h> #define N 1000 int main() { double poly[N+1]={0}; int n,m,i; int exp; double coef; scanf("%d",&n); m=n; for(i=0;i<n;i++) { scanf(" %d %lf",&exp,&coef); poly[exp]

1002. A+B for Polynomials (25)——PAT (Advanced Level) Practise

题目信息: 1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 lin

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

1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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, an

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 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 polyno

1002. A+B for Polynomials (25) (数学啊 ZJU_PAT)

题目链接:http://www.patest.cn/contests/pat-a-practise/1002 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 po

甲级1002 A+B for Polynomials (25)

题目描述: 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

1002 A+B for Polynomials (PAT (Advanced Level) Practice)

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?N?1???? N?2?? a?N?2?

PAT Advanced 1002 A+B for Polynomials (25分)

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?N?1???? N?2?? a?N?2?

PAT:1002. A+B for Polynomials (25) 部分错误

#include<stdio.h> #include<stdlib.h> #include<string.h> //[warning]double 输入%lf,输出%f struct arr { int tag; double data; }arr[1005]; int main() { memset(arr,0,sizeof(arr)); int t1,t2,tmp,maxI=0; //maxI记录最多多少项 double tdata; for(int I=0 ; I