PAT (Advanced Level) Practise - 1009. Product of Polynomials (25)

本文介绍了一种多项式相乘的算法实现,该算法通过读取两个多项式的系数和指数,计算并输出它们的乘积。输入为两个多项式的系数和指数信息,输出同样格式的乘积结果。

1009. Product of 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 Specification:

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

多项式相乘。


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
using namespace std;
#define LL long long
const int maxn = 2200;
const int inf = 0x3f3f3f3f;
double a[maxn];
double b[maxn];
double ans[maxn];

int main()
{
    
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        int k;
        double c;
        cin>>k>>c;
        a[k]=c;
    }
    cin>>n;
    for(int i=1;i<=n;i++){
        int k;
        double c;
        cin>>k>>c;
        b[k]=c;
    }
    for(int i=0;i<=1000;i++){
        for(int j=0;j<=1000;j++){
            ans[i+j]+=a[i]*b[j];
        }
    }
    int p=0;
    int num=0;
    for(int i=2000;i>=0;i--){
        if(ans[i]!=0){
            num++;
           
        }
    }
    printf("%d",num);
    for(int i=2000;i>=0;i--){
        if(ans[i]!=0){
            printf(" %d %.1lf",i,ans[i]);
        }
    }
    printf("\n");
    
}



### Keil C51 编译时找不到 `reg51.h` 文件的问题解决方案 当在 Keil C51 中遇到错误提示:“error: #5: cannot open source input file 'reg51.h': No such file or directory”,这通常表明编译器无法找到所需的头文件 `reg51.h`。以下是可能导致该问题的原因以及对应的解决方法。 #### 原因分析 1. **未安装标准设备支持包** 如果没有正确安装或配置 Keil 的标准设备支持包,则可能缺少必要的头文件,例如 `reg51.h`[^1]。 2. **项目设置中的路径缺失** 即使 `reg51.h` 存在于系统中,但如果项目的包含路径未正确指向这些文件的位置,也会导致类似的错误[^2]。 3. **目标芯片不匹配** 在某些情况下,如果选择了错误的目标芯片型号或者未启用正确的设备选项,也可能引发此类问题[^3]。 4. **Keil 安装损坏或不完整** 若 Keil 软件本身存在安装问题,比如部分组件丢失或被意外删除,同样会触发上述错误消息[^4]。 #### 解决方案 ##### 方法一:确认并修复设备支持包的安装状态 确保已下载并安装适用于所选微控制器系列的标准设备支持 (Device Support) 包。可以通过访问 Keil 官方网站获取最新版本的支持包,并重新安装以覆盖现有数据。 ##### 方法二:调整项目属性里的 Include Paths 配置项 进入 Project -> Options for Target -> C51 Settings 页面,在 "Include Path" 字段补充上实际存放有 `reg51.h` 头文件的具体目录地址;一般而言,默认应该位于 `<Keil Installation Directory>\C51\INC` 下面。 ##### 方法三:验证当前选用的目标器件是否恰当 双击左侧窗口树形结构下的 Target 名称节点展开其子级菜单列表,检查 Output 和 Debugging 设置里面指定的目标 MCU 类型是不是与正在开发的应用程序相吻合。如果不一致的话,请修改成合适的模型再试一次构建操作。 ##### 方法四:重装 Keil 工具链环境 对于怀疑由于软件自身缺陷引起的情况,建议卸载现有的 Keil 版本之后再次执行干净彻底的新一轮部署过程,期间注意勾选所有关联功能模块以便获得完整的运行支撑框架。 ```c // 示例代码片段展示如何引入 reg51.h 并定义端口寄存器变量 #include <reg51.h> sbit LED = P1^0; // 将P1.0脚映射为LED控制信号位 void main(void){ while(1){ LED=~LED; delay_ms(500); // 模拟延时函数调用实现闪烁效果 } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值