PAT A1009 Product of Polynomials(25)
课本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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- pat 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- pat1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PATA 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
随机推荐
- wait()函数
wait()函数:回收僵尸进程 父进程调用wait函数可以回收子进程终止信息.该函数有三个功能: 1) 阻塞等待子进程退出 2) 回收子进程残留资源 3) 获取子进程结束状态(退出原因) /*** z ...
- python 绘制sinx
code import turtle import math turtle.speed() turtle.penup() turtle., * math.sin((-/) * * math.pi)) ...
- springboot(七).springboot整合jedis实现redis缓存
我们在使用springboot搭建微服务的时候,在很多时候还是需要redis的高速缓存来缓存一些数据,存储一些高频率访问的数据,如果直接使用redis的话又比较麻烦,在这里,我们使用jedis来实现r ...
- golang精选100题带答案
能力模型 级别 模型 初级 primary 熟悉基本语法,能够看懂代码的意图: 在他人指导下能够完成用户故事的开发,编写的代码符合CleanCode规范: 中级 intermediate 能够独立完成 ...
- 预处理、const、static、sizeof-为什么inline能很好地取代表达式形式的预定义
1:有如下几种原因: (1)inline定义的类的内联函数,函数的代码被放在符号表中,在使用时直接进行替换(像宏一样展开),没有了调用的开销,效率也很高. (2)类的内联函数也是一个真正的函数.编译器 ...
- EBS登录问题小结
1 网络问题 1)ping IP 2)telnet IP 端口 备注:如果端口能访问则直接跳转,如果不能访问则报错如下所示: 2)配置host文件 如果访问的服务器在内网,则需要配置host信息 3) ...
- torch学习中的难点
https://github.com/zergtant/pytorch-handbook/blob/master/chapter2/2.1.4-pytorch-basics-data-lorder.i ...
- react 闲谈
从事前端一段时间了,公司用的框架都是vue,但是不知为何对react却情有独钟,这是不是所谓的吃着碗里的看着锅里的 哈哈哈 从头好好总结下react吧 小白一个 大神勿喷 瞎说一 react是由两部分 ...
- .netcore多语言解决方案
这里本文使用Microsoft.AspNetCore.Localization来实现多语言的解决方案 默认是包含这个包的,所有不需要再额外安装 首先需要注入我们需要的服务 1.在startup.cs中 ...
- 实现超简单的http服务器
想在Linux下实现一个简单的web Server并不难.一个最简单的HTTP Server不过是一个高级的文件服务器,不断地接收客户端(浏览器)发送的HTTP请求,解析请求,处理请求,然后像客户端回 ...