课本AC代码

#include <cstdio>
struct Poly {
int exp;//指数
double cof;
} poly[1001];//第一个多项式 double ans[2001];//存放结果
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
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 < n; i++) {
int exp;
double cof;
scanf("%d%lf", &exp, &cof); //第二个多项式的指数和系数
for(int j = 0; j < n; j++) {//与第一个多项式中的每一项相乘
ans[exp + poly[j].exp] += (cof * poly[i].cof);
}
}
for(int i = 0; i <= 2000; i++) {
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;
}

自己代码,调试还总是出错

#include <cstdio>
#include <algorithm>
const int max_n = 2100; using namespace std; double p1[max_n][2] = {0.0}, product[max_n] = {0.0};
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n1 = 0, n2 = 0, big = 0;
scanf("%d", &n1);
for(int i = 0; i < n1; i++) {
int cof;
double exp;
scanf("%d %1f", &cof, &exp);//p1[i][0]:系数, p1[i][1]:指数
p1[cof] += exp;
}
/*for(int i = 0; i < n1; i++) {
printf("1: %d %1f \n\n", p2[i], p1[i]);//p1[i][0]:系数, p1[i][1]:指数
}
scanf("%d", &n2);
for(int i = 0; i < n2; i++) {
int cof;
double exp;
scanf("%d %1f", &cof, &exp);//p2[i][0]:系数, p2[i][1]:指数
for(int j = 0; j < n1; j++) {
for(int i = 0; i < 1010; i++) {
product[exp +
}
/*for(int i = 0; i < n1; i++) {
printf("2: %d %1f \n\n", p4[i], p3[i]);//p1[i][0]:系数, p1[i][1]:指数
}
for(int i = 0; i < n2; i++) {
for(int j = 0; i < n1; j++) {
p5[p2[i] + p4[i]] += (p1[i] * p3[i]);
}
}
int num = 0;
for(int i = 0; i <= max_n; i++) {
if(p5[i] != 0.0) num++;
}
printf("%d", num);
for(int i = max_n; i > 0; i--) {
if(p5[i] != 0.0) {
printf(" %d %1f", i, p5[i]);
}
}
return 0;
}

PAT A1009 Product of Polynomials(25)的更多相关文章

  1. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

  2. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

    题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...

  3. PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  4. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  5. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  6. pat 甲级 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  7. pat1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  8. PATA 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  9. 1009 Product of Polynomials (25分) 多项式乘法

    1009 Product of Polynomials (25分)   This time, you are supposed to find A×B where A and B are two po ...

随机推荐

  1. Wox使用指南

    下载安装 从下载地址下载最新版本的 wox ,我下载的是 exe 版的 Wox-1.3.578.exe 下载以后直接安装即可,不会有选择项,安装成功以后会在屏幕上出现一个搜索框,默认失去焦点以后搜索框 ...

  2. win 内网frp反弹到内网liunx

    前提:frp不同系统 但是版本必须完全相同 这是我的两个版本 我这个就是验证frp可以在不同系统之间使用 准备工作 靶机 win2003 ip 192.168.1.132 公网 vps windows ...

  3. app支付宝充值

    首先支付宝需要开通app 支付 然后登录支付宝 ,点击合作伙伴, 进入 开放平台,申请一个应用. 下载支付宝开放平台助手, 生成应用公钥,点击上传 设置进入之前申请的应用,支付宝自动生成支付宝公钥,设 ...

  4. laravel如何从mysql数据库中随机抽取n条数据

    laravel如何从mysql数据库中随机抽取n条数据 一.总结 一句话总结: inRandomOrder():$userQuestions=UserQuestion::where($map)-> ...

  5. Css设置字体

    另,考虑到文件编码问题,在css中推荐使用中文字体的英文表示法,以下附常见中文字体的英文名:Mac OS的一些:Georgia  数字高低起伏Comic Sans MS 好看的英文字体华文细黑:STH ...

  6. 服务器开启FTP功能

    介绍几个比较完整的教程链接 Windows Server 2012 之文件服务器(FTP)

  7. MS SQL 数据类型转换

    MS SQL 转换数据类型 select cast(列A as int) 列A select convert(int,列A) 列A --转字符串为int select len(ltrim(str('数 ...

  8. <JavaScript>“浏览器模式”和“文档模式”之间的区别

    只有IE浏览器中才会有“浏览器模式”和“文档模式”,兼容性视图涉及两个重要的功能便是“浏览器模式[browser mode]”和“文档模式[document mode]”,在IE8/IE9中按F12键 ...

  9. ShockUtil振动工具类

    import android.app.Activity; import android.app.Service; import android.content.Context; import andr ...

  10. HttpURLConnection 多线程下载

    影响下载的速度 * 宽带的带宽 * 服务器的限制 * 服务器的资源固定,开启的线程越多抢占的资源就越多 import java.io.InputStream; import java.io.Rando ...