A1009 Product of Polynomials (25)(25 分)

本文介绍了一种解决多项式乘法问题的算法实现方法,输入两个多项式A和B,输出它们的乘积。文章提供了C语言实现的源代码,并讨论了变量初始化的重要性及最高幂次数的边界条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A1009 Product of Polynomials (25)(25 分)

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 a~N1~ N2 a~N2~ ... NK a~NK~, where K is the number of nonzero terms in the polynomial, Ni and a~Ni~ (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

思考

先考虑怎么存第一个样例

比起初试,还是机试爆零更可怕一点,所以确实是在大三下没有把握住机会啊,这学期有3门课,不应该那么烂的。

最高幂次数是2000,因为最大情况是1000*1000。

另外全局变量初始化不赋值,c语言默认处理为0啊,那么养成初始化赋值的习惯是极好的。

【c语言问题系列教程之一】变量声明和初始化 - 优快云博客 https://blog.youkuaiyun.com/mylinchi/article/details/52652595

C语言中全局变量初始化的重要性!!! - 优快云博客 https://blog.youkuaiyun.com/macrohasdefined/article/details/8814804

AC代码

#include<stdio.h>
struct Poly{
    int exp;
    double cof;
}poly[1001];//幂次数决定个数,正如数组下标是幂次数一样 
double ans[2005]={0};//存放结果 
int main(){
    int n,m,number=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %lf",&poly[i].exp ,&poly[i].cof );
    }//读入第一个多项式 
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        int exp;
        double cof;
        scanf("%d %lf",&exp,&cof);//读入第二个多项式的一项 
        for(int j=0;j<n;j++){
            ans[exp+poly[j].exp]+=(cof*poly[j].cof);//这个写法从A1042起步 
        }   
    } 
    for(int i=0;i<=2000;i++){//这里漏掉一个最高幂次数2000,就有两个测试点过不去 
        if(ans[i] !=0.0) number++;
    } 
    printf("%d", number);
    for(int i=2000;i>=0;i--){
        if(ans[i] !=0.0){
            printf(" %d %.1f",i ,ans[i]);//输出控制要注意 
        }
    }
    return 0;
} 

转载于:https://www.cnblogs.com/lingr7/p/9389375.html

3DMine E:\00-刚果(金)新矿业\1--2025年\03、验收数据\6月验收\6月交接数据\6月验收底图(已更新至0624交接).3ds, 3DMine String File file_version=3DMine_2009 1,7,0,1.00,1.00,1.00,0,0.5,0,Continuous,0624XK5交接 2,7,0,1.00,1.00,1.00,0,0.5,0,Continuous,0624XK9交接 3,7,0,1.00,1.00,1.00,0,0.5,0,Continuous,1 4,7,0,1.00,1.00,1.00,0,0.5,0,Continuous,范围线 5,7,0,1.00,1.00,1.00,0,0.5,0,Continuous,界线 0,0,0,0,0,0,0,0, 3,8786919.71000,451915.69700,1308.81500,hp1474,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786863.21200,451888.23900,1290.13700,hp3051,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786835.08600,451964.11300,1287.88000,hp3105,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786859.85500,451993.22600,1299.00000,hp1547,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8787060.76762,452008.51951,1359.65897,G2031, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786935.94300,451877.72700,1300.95200,hp2697,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786855.12800,451878.27500,1287.72100,hp3082,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786936.66400,451840.95000,1289.51400,hp354,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786916.79600,451890.37000,1299.48200,hp2735,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786926.05500,453272.66600,1323.35700,d1814,\ 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786667.11900,452621.48900,1333.50500,2024.3.2原始地貌727, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786921.43500,451890.52300,1300.91400,hp2708,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786853.81600,451975.05700,1295.25500,hp1556,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786977.06100,451847.40200,1293.41500,hp84,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786865.68200,451965.13900,1298.65500,hp1558,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786950.45300,451895.76400,1310.28100,hp2660,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786889.20800,451997.80900,1309.83800,hp1510,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786964.69600,451849.94500,1291.37500,hp3408,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786939.91000,451898.51300,1309.79000,hp3009,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786854.29100,451962.89300,1296.18100,hp1543,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786917.05000,451892.91400,1300.21900,hp2717,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786930.05300,451907.43000,1309.99000,hp2663,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786975.39300,451834.29400,1291.90700,hp69,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786870.88500,451974.95800,1300.84000,hp1591,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786576.36000,451390.08400,1351.97400,A61, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786998.98200,451482.88200,1311.77700,B41, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786976.67000,451899.19900,1310.87100,hp3421,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786865.32900,451885.90700,1290.06000,hp3021,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786966.34500,451855.81900,1292.89700,hp3404,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786925.50900,451885.05300,1299.94600,hp2703,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786891.25600,451925.36800,1299.57700,hp2838,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786942.02200,451836.42300,1292.26600,hp358,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786929.36700,451882.47200,1300.29600,hp2710,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786965.16100,451858.90800,1293.99200,hp2707,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786415.29300,451540.29400,1349.02300,A24, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786421.40700,451503.67100,1350.90600,A219, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786834.49000,451932.04800,1290.99200,hp3058,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786846.90800,451907.62400,1292.45900,hp3027,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786864.40000,451958.72600,1297.30900,hp1567,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786962.80700,451883.30900,1306.70000,hp3008,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786965.01000,451877.93300,1303.28100,hp2998,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786964.74900,451851.60600,1291.53400,hp3407,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8787037.02500,453111.89400,1371.02600,tr554, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786959.94100,451843.44000,1290.05000,hp3414,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786414.56500,451557.34200,1347.38400,A21, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786599.87700,451358.69100,1351.49100,A179, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786962.17000,451861.77100,1295.79600,hp2701,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786979.67700,451829.03000,1292.25800,hp65,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786869.41000,451881.88600,1290.13600,hp3065,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786418.98200,451584.68800,1345.18300,A17, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786930.17800,451913.61800,1311.36000,hp2655,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786915.21600,451928.75500,1308.64600,hp1447,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786931.58200,451913.02400,1311.48100,hp2656,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786921.94100,451886.91300,1299.78600,hp2698,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786540.83700,451848.79500,1334.52900,a1189, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786904.09300,451948.41400,1307.91100,hp1480,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786559.43000,451824.01200,1337.35500,a639, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786947.68300,451890.34500,1307.72400,hp3000,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8787309.49800,452596.82400,1362.11500,tr24, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8787606.06800,450825.82500,1369.82700,806,\ 0,0.000,0.000,0.000,-1,,1.000,-1.00,-1.00,-1.00,7 3,8786732.20600,451317.25700,1356.22600,A153, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786831.97000,451287.56300,1361.72600,A132, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786938.53900,451840.64600,1290.45100,hp342,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786906.12200,451894.89000,1297.87000,hp2700,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8787383.11200,451642.36700,1264.52400,L67, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786733.10300,452629.35200,1337.96700,B4, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786408.40100,451523.09700,1350.08200,A223, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786976.63300,451838.18100,1292.79700,hp71,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786559.45600,451402.51600,1351.98200,A57, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786849.64200,451902.12600,1292.09200,hp3032,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786845.62500,451278.68700,1362.03200,A129, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786530.55600,451422.21100,1352.19800,A380, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786854.66900,451881.38000,1288.05400,hp3070,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786980.92700,451827.69100,1292.18100,hp64,Auto 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786419.53000,451528.02300,1350.06500,A26, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786856.92800,452675.55100,1396.93500,144, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786585.93500,451429.94200,1353.03700,A1009, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786411.19500,451622.35800,1342.60800,A241, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8787168.50600,453016.17800,1377.88800,tr511, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 3,8786715.12100,451333.56500,1355.87100,A90, 0,0.000,0.000,0.000,0,,1.000,-1.00,-1.00,-1.00,7 能否解释一下这个软件的数据结构是什么意思
最新发布
07-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值