1009. Product of Polynomials (25)

简介: #include using namespace std;int main(int argc, const char * argv[]) { double a[1001] = {0}, b[1001] = ...


#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    double a[1001] = {0}, b[1001] = {0}, p[2001] = {0};
    int m, n;
    scanf("%d", &m);
    double c;
    int e;
    
    for (int i = 0; i < m; i++) {
        scanf("%d %lf", &e, &c);
        a[e] = c;
    }
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %lf", &e, &c);
        b[e] = c;
    }
    
    for (int i = 0; i <= 1000; i++) {
        for (int j = 0; j <= 1000; j++) {
            if (a[i] && b[j]) {
                p[i+j] += a[i] * b[j];
            }
        }
    }
    
    int cnt = 0;
    for (int i = 0; i <= 2000; i++) {
        if (p[i]) {
            cnt++;
        }
    }
    
    printf("%d", cnt);
    for (int i = 2000; i >=0 ; i--) {
        if (p[i]) {
            printf(" %d %0.1lf", i, p[i]);
        }
    }
    printf("\n");
    
    return 0;
}

简析:采用数组存储。为了简单起见,循环都取题目中的上下界。浮点数的具体问题不存在的。


目录
相关文章
|
3月前
|
数据库 Python
Cartesian product
【7月更文挑战第5天】
46 0
|
5月前
|
数据挖掘
Commerce Cloud 里的 Product Catalog 和 Product Categories 的联系
Commerce Cloud 里的 Product Catalog 和 Product Categories 的联系
|
内存技术
Obtain the data code of Taobao JD1688alibaba lazada shop product details page
1、 Data types of e-commerce APIs The types of data provided by e-commerce APIs are diverse and can generally be divided into the following categories: Product data: Product ID, Product Name, Product Price, Inventory, etc. Transaction data: order number, payment time, recipient, etc. Store data
Obtain the data code of Taobao JD1688alibaba lazada shop product details page
SAP RETAIL MM42进入商品的销售视图系统提示: No basic purchase price relevant to pricing found with schema RM0000
SAP RETAIL MM42进入商品的销售视图系统提示: No basic purchase price relevant to pricing found with schema RM0000
SAP RETAIL MM42进入商品的销售视图系统提示: No basic purchase price relevant to pricing found with schema RM0000
CRM PRODUCT_MAT, BDOC和customer product id修改
CRM PRODUCT_MAT, BDOC和customer product id修改
108 0
CRM PRODUCT_MAT, BDOC和customer product id修改
|
Web App开发 开发者
Cloud for Customer Restriction and Exclusion Product Lists
当我试图在SAP Cloud for Customer的销售订单里添加一个新产品时,遇到错误消息:
Cloud for Customer Restriction and Exclusion Product Lists
无法添加某个relationship给SAP CRM Product category的一个可能原因
无法添加某个relationship给SAP CRM Product category的一个可能原因
132 0
无法添加某个relationship给SAP CRM Product category的一个可能原因
SAP Structured product - component set
Created by Jerry Wang, last modified on Sep 30, 2016
SAP Structured product - component set
使用ABAP代码创建新的product category
使用ABAP代码创建新的product category
98 0
使用ABAP代码创建新的product category
SAP CRM Product hierarchy,Category和Application的三个问题
SAP CRM Product hierarchy,Category和Application的三个问题
176 0
SAP CRM Product hierarchy,Category和Application的三个问题