五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【Python】PAT甲級 A1009:Product of Polynomials

2021-02-11 19:57 作者:曉霧喵  | 我要投稿

題目內(nèi)容

This time, you are supposed to find ×?where? and??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:

where? is the number of nonzero terms in the polynomial, and (=1,2,?,) are the exponents and coefficients, respectively. It is given that 1?K?100? N_K < ...?< N_2 < N_1 ?10000?NK<?<N2<N1?1000..

Output Specification:

For each test case you should output the product of and ?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 up to 1 decimal place.

Sample Input:

Sample Output:

題目要點

本題 25 分,是比較簡單的模擬題。在輸入時,Python可以不用考慮給定的,直接用數(shù)組切片隔位取指數(shù)列表、系數(shù)列表,再用zip()構(gòu)造字典。

這道題與前面文章提到的A1002問題類似,一些相似的解法、代碼在前文中有提到,這里不在贅述。

重點需要考慮的是如何將多項式的指數(shù)和對應(yīng)系數(shù)映射。C/C++可以用數(shù)組下標(biāo)作為指數(shù),數(shù)組浮點數(shù)值為對應(yīng)系數(shù)。這里Python使用字典比較方便,而且考慮到兩個多項式的指數(shù)項不一定相同,在求和時要指數(shù)項系數(shù)對應(yīng)相加,Python可以使用集合的求并集|運算符實現(xiàn)。

注意,測試點6是非零系數(shù)項個數(shù),也就是為0的情況,這時候只輸出0。如果有多余空格會出現(xiàn)“格式錯誤”。

AC 源代碼



【Python】PAT甲級 A1009:Product of Polynomials的評論 (共 條)

分享到微博請遵守國家法律
沐川县| 乃东县| 乌鲁木齐市| 分宜县| 鸡东县| 泰安市| 宁明县| 安化县| 彭泽县| 金塔县| 西安市| 丰镇市| 西林县| 怀宁县| 南丰县| 思南县| 玉门市| 徐水县| 隆昌县| 息烽县| 临沧市| 剑川县| 礼泉县| 吉木乃县| 隆安县| 沙河市| 柳州市| 定襄县| 华阴市| 嵩明县| 三台县| 潜江市| 达日县| 和龙市| 长春市| 客服| 安多县| 仁布县| 普宁市| 石嘴山市| 乌兰察布市|