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. hdu4414(DFS 找十字架数量)

    Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...

  2. jquery实现城市选择器效果(二级联动)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. sql 清除日志空间

    USE DBCenter GO SELECT file_id, name FROM sys.database_files; 查找日志名称 USE DBCenter ; GO ALTER DATABAS ...

  4. JS判断字符串是否包含某字符串 indexOf()方法使用

    定义和用法 indexOf()方法可返回某个指定的字符串值在字符串中首次出现的位置. 开始的.如果没有找到子字符串,则返回 -1. 示例: <script type="text/jav ...

  5. ASP.NET页面之间传递值的几种方式(转载)

    页面传值是学习asp.net初期都会面临的一个问题,总的来说有页面传值.存储对象传值.ajax.类.model.表单等.但是一般来说,常用的较简单有QueryString,Session,Cookie ...

  6. 里氏替换原则LSP(继承规范)

    继承的优点: 1.代码共享,减少创建类的工作量,每个子类都拥有父类的方法和属性. 2.提高代码的重用性. 3.子类可以形似父类,但又异于父类. 4.提高代码的可扩展性,实现父类的方法就可以“为所欲为” ...

  7. Klockwork告警常见错误

    下面列举的是Klockwork告警中常见的告警形式,这些情况在编译阶段都不会报出来语法上的错误,并且在运行阶段执行到的概率很小.但是在某些场景下一旦执行到了这些语句, 很可能引起进程的跑飞和挂起.   ...

  8. 发布Activex全过程

    C#制作.打包.签名.发布Activex全过程 一.前言 最近有这样一个需求,需要在网页上面启动客户端的软件,软件之间的通信.调用,单单依靠HTML是无法实现了,因此必须借用Activex来实现.由于 ...

  9. 4605 Magic Ball Game

    先离线记录所有询问,然后用dfs在线记录当前节点的所有父亲结点,父亲结点分为两类,一个从左边过来,一个从右边过来,分别开一个数组. 数据需要离散化,刚开始用lower_bound写,一直wa..,用二 ...

  10. C#中 如何执行带GO的sql 语句

    C#中是不允许执行带GO的sql 语句的, 如何做呢? 思路就是将带GO的sql语句转化为分段执行, 但在同一事务内执行. 扩展方法是个很不错的主意, 但是尽量不要影响原来的cmd的一些东东, 如 c ...