日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

1002 A+B for Polynomials (25分)_29行代码AC

發(fā)布時(shí)間:2024/2/28 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1002 A+B for Polynomials (25分)_29行代码AC 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

立志用最少的代碼做最高效的表達(dá)


PAT甲級(jí)最優(yōu)題解——>傳送門(mén)


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:
KN?1a?N1N2aN2…N?KaNKK N?1 a?N1 N2 aN2 … N?K aNKKN?1a?N1N2aN2N?KaNK where K is the number of nonzero terms in the polynomial, N?iN?iN?i and aNi??(i=1,2,?,K)aNi?? (i=1,2,?,K)aNi??(i=1,2,?,K) are the exponents and coefficients, respectively. It is given that 1≤K≤101≤K≤101K100≤NK<?<N?2<N1≤10000≤NK<?<N?2<N1≤10000NK<?<N?2<N11000.

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


注意要點(diǎn):
1、如果相加后總多項(xiàng)式為0,則輸出0
2、如果某一項(xiàng)為0,則不輸出


#include<bits/stdc++.h> using namespace std; double s[1010]; int main() {int k1; cin >> k1; while(k1--) {int x; double d; cin >> x >> d;s[x] += d;}cin >> k1; while(k1--) {int x; double d; cin >> x >> d;s[x] += d;}int num = 0;for(int i = 1009; i >= 0; i--) if(s[i] != 0) num++; if(num == 0) cout << 0;else {cout << num;for(int i = 1009; i >= 0; i--) {if(s[i] != 0) printf(" %d %.1lf", i, s[i]);}}putchar('\n');return 0; }

耗時(shí)

總結(jié)

以上是生活随笔為你收集整理的1002 A+B for Polynomials (25分)_29行代码AC的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。