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 ...
随机推荐
- Mysql切割字符串
我们常常会遇到需要处理字段中字符串的需求,包括切割.拼接以及搜索等等,在这里介绍几个常用的切割字符串的函数,首先我们在表格中加入我们的实验字段值:https://www.cnblogs.com/Yao ...
- delphi中的退出程序的确认问题
在formclose中用if Application.MessageBox('你确认要退出吗?','请确认',MB_YesNo+MB_IconQuestion)=IDno then begin ... ...
- JS leetcode 搜索插入位置 题解分析
壹 ❀ 引 今天来做一道特别特别简单的题,来自leetcode35. 搜索插入位置,题目描述如下: 给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会 ...
- fmt、变量、常量
fmt包 fmt包主要用于打印数据,常用的有Printf.Print.Printf // 文件所属包 package main // 导入fmt包,主要用于打印数据 import "fmt& ...
- Python枚举类型enum
为什么需要枚举 枚举(Enum)是一种数据类型,也是一种特别的类,是绑定到唯一值的符号表示,可以使用它来创建用于变量和属性的常量集枚举类可以看成是一个下拉菜单,给出特定的选项且这些选项不可修改,更贴近 ...
- Java设计模式-访问者模式Visitor
介绍 访问者模式(Visitor Pattern),封装一些作用于某种数据结构的各元素的操作,它可以在不改变数据结构的前 提下定义作用于这些元素的新的操作. 主要将数据结构与数据操作分离,解决 数据结 ...
- logback日志组件使用案例
关于logback: http://www.cnblogs.com/warking/p/5710303.html 官方文档 使用logback: idea创建maven项目 修改pom.xml添加依赖 ...
- Java并发编程实例--19.在一个锁中使用多个条件
一个锁可能关联了一个或多个条件.这些条件可以在Condition接口中声名. 使用这些条件的目的是去控制一个锁并且可以检查一个条件是true或false,如果为false,则暂停直到 另一个线程来唤醒 ...
- 2021-10-11 vue的第三方组件二次封装
原理 v-bind="$attrs"继承所有属性和props. v-on="$listeners"继承所有的方法. <template> <d ...
- zip压缩模块,tarfile压缩模块,包和模块,format格式化的复习--day17
1.zipfile模块 import zipfile #导入模块 1.压缩文件 (1)创建压缩包 参数1压缩包名字,参数2以w模式创建,参数3压缩固定写法 zf = zipfile.ZipFile(& ...