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. poj3984迷宫问题

    一个5 × 5的二维数组,表示一个迷宫.其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线. 很简单的一道题,迷宫问题,一般都选择两种优先搜索 ...

  2. (翻译) Android Accounts Api使用指南

    本文翻译自Udinic的文章Write your own Android Authenticator,可能需要FQ才能阅读.这是译者目前能找到的介绍如何使用Android的Accounts Api最好 ...

  3. Java 简单工厂模式

    首先 定义一接口 package com.org; public interface SampleInterface { public void print(String s); } 定义两个接口的实 ...

  4. 我的Emacs折腾经验谈(二) Emacs上手难的原因

    既然之前说过要写我怎么继续折腾Emacs的,过了一个星期这里就是第二篇了,突然觉得我把blog这样分节不是很好,每次可能要凑一些东西才有该有的篇幅,而且说的东西可能东一点西一点,这样一篇看下来不利于检 ...

  5. 对比AutoResetEvent和ManualResetEvent

    ManualResetEvent和AutoResetEvent 比较 ManualResetEvent和AutoResetEvent都继承自EventWaitHandler,它们的唯一区别就在于父类 ...

  6. APP类别之比较与分析

    大数据应用:五大地区喜新厌旧游戏APP类别之比较与分析 前阵子笔者开发了一套系统可以用来收集亚洲五大地区上架APP的每日排名信息,希望观察出五大地区在APP上的喜好和使用程度之间的相异性. 所以,在下 ...

  7. [置顶] Adapter详解

    动态添加数据适配器adapter Adapter是适配器,许多UI组件需要搭配Adapter来显示界面,例如Spinner与ListView,另外当我们需要动态的添加数据给UI组件时就需要Adapte ...

  8. java如何避免死锁

    在有些情况下死锁是可以避免的.本文将展示三种用于避免死锁的技术: 加锁顺序 加锁时限 死锁检测 加锁顺序 当多个线程需要相同的一些锁,但是按照不同的顺序加锁,死锁就很容易发生. 如果能确保所有的线程都 ...

  9. ASP.NET Zero--9.一个例子(2)商品分类管理-列表

    1.创建实体类 参考:http://www.cnblogs.com/farb/p/4923137.html 在Core(领域层)项目下新建一个目录Entities,在此目录下新建一个Category类 ...

  10. CSS倒影

    前面的话   CSS倒影目前只有chrome和safari浏览器支持,且需要添加-webkit-前缀.本文将详细介绍CSS倒影box-reflect 语法 -webkit-box-reflect 初始 ...