1009. Product of Polynomials (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

This time, you are supposed to find A*B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < ... < N2 < N1 <=1000.

Output Specification:

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

Sample Input

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output

3 3 3.6 2 6.0 1 1.6
#include"iostream"
#include "algorithm"
#include <math.h>
#include <iomanip>
#include"string.h"
#include "vector"
using namespace std;
#define max 3000
struct Poly
{
int index;//指数
float factor;//系数
}; int main()
{
vector<double> result;
int k1,k2;
cin >> k1;
vector<Poly> p1(k1);
for(int i=0;i<k1;i++)
cin >> p1[i].index >> p1[i].factor;
cin >> k2;
vector<Poly> p2(k2);
for(int i=0;i<k2;i++)
cin >> p2[i].index >> p2[i].factor;
result.assign(max+1,0.0);
int t=0;
for(int i=0;i<k1;i++)
for(int j=0;j<k2;j++)
{
Poly p;
p.index = p1[i].index+p2[j].index;
p.factor = p1[i].factor*p2[j].factor;
result[p.index] +=p.factor;
}
int k=0; for(int i=max;i>=0;i--)
{
if(fabs(result[i])>1e-6)
{
k++;
}
}
cout<<k;
for(int i=max;i>=0;i--)
{
if(fabs(result[i])>1e-6)
{
cout<<" "<<i<<" ";
cout<<setiosflags(ios::fixed);
cout.precision(1);
cout<<result[i];
}
}
cout<<endl;
return 0;
}

  


浙大pat1009题解的更多相关文章

  1. 浙大pat1050题解

    1050. String Subtraction (20) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Given two string ...

  2. 浙大pat1020题解

    1020. Tree Traversals (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  3. 浙大pat1013题解

    1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  4. 浙大pat1042题解

    1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...

  5. 浙大pat1019题解

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  6. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  7. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  8. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  9. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

随机推荐

  1. “git push”后返回“Error 403”解决方法

    问题描述: 1,mac ox系统,terminal上运行命令git push出现403错误: 2,代码是在别人的github(暂且叫origin branch吧)上克隆的,修改和添加了部分代码后欲提交 ...

  2. java遍历Set集合

    class Person{ private String name; private int age; public Person(String name,int age){ this.name = ...

  3. javascript call()函数

    js中的call()函数,简单的说就是用来纠正指正的吧! 调用一个对象的方法,用另一个对象替换当前对象,这样说显得相当的空洞与抽象,实例说明一切! <script type="text ...

  4. thrift之默认传输类TTransportDefaults和虚拟传输类TVirtualTransport

    默认传输类TTransportDefaults提供了抽象类TTransport的默认实现,实现了非虚拟的方法(*_virt) read(), readAll(), write(),borrow() a ...

  5. [Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器

    [Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器   Redis相信玩开源,大数据的朋友们并不陌生,大家最熟悉的使用者就是新浪微博,微博的整体数据缓存都是 ...

  6. 转载:JavaScript多线程编程简介

    虽然有越来越多的网站在应用AJAX技术进行开发,但是构建一个复杂的AJAX应用仍然是一个难题.造成这些困难的主要原因是什么呢?是与服务器的异步通信问题?还是GUI程序设计问题呢?通常这两项工作都是由桌 ...

  7. bat编程基本知识

    1 声明变量 ::注意=前后不要留空格.随便说一下,在bat中,连续两个冒号表示注释 set var1=test 如果要引用这个变量的话,可以这样写:%var1% 2 echo off/on echo ...

  8. PHP生成缩略图函数

    function img_create_small($big_img, $width, $height, $small_img) { // 大图文件地址,缩略宽,缩略高,小图地址$imgage = g ...

  9. 如何让msvsmon.exe 以服务方式运行

    通常我们在VS上调试程序用的都是msvsmon.exe, 使用管理员权限运行再选项设置任何人可以调试就可以了,而这个在绝大多数情况下都没有问题.而我想说的就是特殊的情况,跟msvsmon的运行权限相关 ...

  10. LearnCpp.com

    LearnCpp.com is a totally free website devoted to teaching you to program in C++. Whether you’ve had ...