课本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. ubuntu 16.04安装gitlab,然后汉化

    1 前期准备 电脑配置:windows7 ,内存8GB以上(因为有4GB左右要分配给虚拟机中的ubuntu) 虚拟机:VBOX Linux系统:ubuntu16.04 64bit 2 Gitlab的搭 ...

  2. 早停!? earlystopping for keras

    为了获得性能良好的神经网络,网络定型过程中需要进行许多关于所用设置(超参数)的决策.超参数之一是定型周期(epoch)的数量:亦即应当完整遍历数据集多少次(一次为一个epoch)?如果epoch数量太 ...

  3. shell脚本中根据端口号kill对应的应用进程

    一.使用情景 在Jenkins的自动部署中,每次重新部署我们都需要先关闭原先的应用进程,然后重新部署启动.在使用tomcat时,我们可以通过startup.sh和shutdown.sh进行对应操作.但 ...

  4. PostgreSQL 当月最后一天的工作日 , 计算日期是星期几

    可以用pg自带函数select extract(dow from current_date),之所以没用主要是展示一下通过数学方法计算日期的原理. drop function if exists ge ...

  5. 2965 -- The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27893 ...

  6. SoundPool 播放短声音

    SoundPool 最大只能申请1M的内存空间,只能用一些很短的声音片段,而不是用它来播放歌曲或者做游戏背景音乐. 使用 SoundPool 播放短声音实现步骤如下: // 创建SoundPool实例 ...

  7. RabbitMQ学习之:(二)介绍 (转贴+我的评论)

    转自:http://lostechies.com/derekgreer/2012/03/05/rabbitmq-for-windows-introduction/ RabbitMQ for Windo ...

  8. java.lang.reflect.Method.getAnnotation()方法示例【通过反射获取到方法对象再获取方法对象上的注解信息】

    转: java.lang.reflect.Method.getAnnotation()方法示例 java.lang.reflect.Method.getAnnotation(Class <T&g ...

  9. 计算机组成原理 — FPGA 现场可编程门阵列

    目录 文章目录 目录 FPGA FPGA 的应用场景 FPGA 的技术难点 FPGA 的工作原理 FPGA 的体系结构 FPGA 的开发 FPGA 的使用 FPGA 的优缺点 参考文档 FPGA FP ...

  10. webpy简单入门---1

    1. 2. 3. 4.