首页 > 其他分享 >PAT 甲级 1009 Product of Polynomials

PAT 甲级 1009 Product of Polynomials

时间:2023-03-05 17:59:15浏览次数:51  
标签:case Product PAT arr int cin Polynomials ++ each

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​​​​ ... N​K​​ a​N​K​​​​

where K is the number of nonzero terms in the polynomial, N​i​​ and a​N​i​​​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10, 0≤N​K​​<⋯<N​2​​<N​1​​≤1000.

Output Specification:

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

Sample Input:

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output:

3 3 3.6 2 6.0 1 1.6

Accepted Code

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n1, n2, a, cnt;
 4 double b, arr[1001] = {0.0}, ans[2001] = {0.0};
 5 
 6 int main()
 7 {
 8     cin >> n1;
 9     for(int i = 0; i < n1; i ++)
10     {
11         cin >> a >> b;
12         arr[a] = b;
13     }
14     cin >> n2;
15     for(int i = 0; i < n2; i ++)
16     {
17         cin >> a >> b;
18         for(int j = 0; j < 1001; j ++)
19             ans[j + a] += arr[j] * b;
20     }
21     for(int i = 0; i <= 2000; i ++)
22         if(ans[i] != 0.0) cnt ++;
23     cout << cnt;
24     for(int i = 2000; i >= 0; i --)
25         if(ans[i] != 0.0)
26             cout << " " << i << " " << fixed << setprecision(1) << ans[i];
27     return 0;
28 }

 

标签:case,Product,PAT,arr,int,cin,Polynomials,++,each
From: https://www.cnblogs.com/marswithme/p/17181077.html

相关文章

  • 《设计模式之禅》Strategy_Pattern--策略模式
    写在前面设计模式之禅这本书也是博主看了几本设计模式的开头才决定以这本书作为学习设计模式的资料。像小傅哥的重学Java设计模式,好处是以真实的项目案例的逻辑来搭配设计模......
  • 高性能 Jsonpath 框架,Snack3 3.2.57 发布
    Snack3,一个高性能的JsonPath框架借鉴了Javascript所有变量由var申明,及Xmldom一切都是Node的设计。其下一切数据都以ONode表示,ONode也即Onenode之意,代表任何......
  • NetCore 之 DispatchProxy
    如何使用Dispatchproxy封装RESTAPI,让API调用更简单。1、创建HttpClientDispathProxy类继承自DispatchProxypublicclassHttpClientDispathProxy<TInterface>:D......
  • 【总结】2023-03-03 Rook Path
    RookPath题意有一个\(n\)行\(m\)列的矩阵,有一只乌鸦在\((x_1,y_1)\)上,它想要去\((x_2,y_2)\)。乌鸦可以飞\(k\)次:假设乌鸦现在在\((x,y)\),它可以选择以下......
  • pat乙级1023 组个最小数
    #include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>intmain(){inta[10];for(inti=0;i<10;i++){scanf......
  • pat乙级1022 D进制的A+B
    #include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#defineN100intmain(){inta,b,d;scanf("%d%d%d",&a,&b,&d);intnum......
  • ChainofResponsibility Pattern
    责任链模式:参考:https://www.runoob.com/design-pattern/chain-of-responsibility-pattern.html避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象......
  • pat乙级 1021个位数统计
    #include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#definek1000intmain(){inti=0;charnum[k];for(i=0;i<k......
  • .net使用DispatchProxy
    实现动态aop并注入用表达式树调用目标方法创建一个DynamicDispatchProxy类继承DispatchProxy,字典key最好是由路劲名称+方法参数组成 publicclassDynamicDispatchPr......
  • python爬虫-xpath基础
    #准备一个html格式文档doc='''<div><ul><liclass="item-0"><ahref="https://ask.hellobi.com/link1.html">firstitem</a></li><liclas......