PAT 甲级【1009 Product of Polynomials】
/*
- 系数为0不输出
- 貌似runtime异常也显示答案不正确
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer; public class Main {
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
in.nextToken();
int n = (int) in.nval;
int[] N = new int[n];
double[] a = new double[n];
for (int i = 0; i < n; i++) {
in.nextToken();
N[i] = (int) in.nval;
in.nextToken();
a[i] = in.nval;
}
in.nextToken();
int m = (int) in.nval;
int[] M = new int[m];
double[] b = new double[m];
for (int i = 0; i < m; i++) {
in.nextToken();
M[i] = (int) in.nval;
in.nextToken();
b[i] = in.nval;
}
double[] map = new double[N[0] + M[0]+1];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
map[N[i] + M[j]] += a[i] * b[j];
}
}
int k = 0;
for (int i = N[0] + M[0]; i >= N[n - 1] + M[m - 1]; i--) {
if (Math.abs(map[i]) > 0.0001) {
k++;
}
}
System.out.print(k);
for (int i = N[0] + M[0]; i >= N[n - 1] + M[m - 1]; i--) {
if (Math.abs(map[i]) > 0.0001) {
System.out.print(String.format(" %d %.1f", i, map[i]));
}
}
System.out.println();
}
}
PAT 甲级【1009 Product of Polynomials】的更多相关文章
- 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 ...
- PAT甲级——1009 Product of Polynomials
PATA1009 Product of Polynomials Output Specification: For each test case you should output the produ ...
- 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)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
- PAT 1009 Product of Polynomials
1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two p ...
- PTA (Advanced Level) 1009 Product of Polynomials
1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...
随机推荐
- 双端队列(deque)--python
Python中的双端队列(deque)是一种特殊的数据结构,它允许在队列的两端进行插入和删除操作12.双端队列可以看成栈和队列的结合3.在Python中,我们可以使用collections模块中的de ...
- Python脚本之将一个文件夹划分多个文件夹和批量创建文件夹
import os import shutil # 要移出的文件路径 path = r"C:\old_dir" # 新创建多个文件夹的路径 new_path = r"C: ...
- yapi 个人空间 这个分组的问题
总结:yapi个人空间分组的问题,我暂时不用理睬 他自己自由,但是 不允许他 创建非个人空间的分组.这点留意 避免不统一.所有的分组都必须我自己来创建,不允许他们私自创建.
- Redis Desktop Manager 0.9.3.817 最后一版免费版,新版要收费
链接: https://pan.baidu.com/s/1wyELUhOn_rumFecNAS7L0A 提取码: 1631 版本是两三个月前,我从官网下载的,然后顺便存到了我的移动硬盘上.0 ...
- NC15976 小C的周末
题目链接 题目 题目描述 愉快的周末到了,小C和他的N-1个朋友买了M个游戏,游戏编号从1~M.每个游戏都是多人游戏,他们打算周末一起打游戏. 小C的每个朋友都决定好了要玩哪一款游戏(会有一组人打同一 ...
- OCR 01: EasyOCR
Catalog OCR 01: EasyOCR OCR 02: Tesseract-OCR OCR 03: PaddleOCR Related Links Official site with onl ...
- Centos7和Centos8的NFS配置
Centos7和Centos8的NFS配置几乎是完全一样的 服务端 Centos7默认安装了rpcbind, nfs-utils, 其中rpcbind的服务默认是启用的, nfs-utils默认是禁用 ...
- BUG管理系统(Mantis)迁移实战
Mantis迁移实战 名词解释 Mantis: 开源的BUG管理平台Mantis,也做MantisBT. 同档次产品有EasyBUG,QC,BugFree,Bugzila. Xa ...
- Java I/O 教程(三) FileOutputStream类
Java FileOutputStream 用于将字节数据写入文件. 如果你需要将原始数据写入文件,就使用FileOutputStream类. Java.io.FileOutputStream cla ...
- Java 基本数据类型之间的运算规则
1 /*** 2 * 基本数据类型之间的运算规则 3 * 4 * 前提:7中基本数据类型运算 5 * 6 * 1.自动类型提升: 7 * 当容量小的类型与容量大的数据类型的变量做运算时,结果自动提升为 ...