浙大pat1009题解
1009. Product of Polynomials (25)
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题解的更多相关文章
- 浙大pat1050题解
1050. String Subtraction (20) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Given two string ...
- 浙大pat1020题解
1020. Tree Traversals (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- 浙大pat1013题解
1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- 浙大pat1042题解
1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...
- 浙大pat1019题解
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
随机推荐
- 哞哞快的 C# 高斯模糊实现(续)
昨天刚写了<哞哞快的 C# 高斯模糊实现>,里边提到了用原作者的方法实现对图像快速的高斯模糊处理,说实话,我没看懂,主要是没看懂原理,怎么就“把图片给处理了”,大概是调用了 GDIPlus ...
- GEF-whole-upload教程中遇到的问题及解决方案
最近在学习GEF开发,使用的是GEF-whole-upload这个教程.由于教程当时所使用的版本与本人使用的版本有一些差异,中间出现了不少问题,现在将解决方案分享给大家. 本人使用的Eclipse版本 ...
- 新时代的Vim C++自动补全插件 clang_complete
Vimer的福音 新时代的Vim C++自动补全插件 clang_complete 使用vim的各位肯定尝试过各种各样的自动补全插件,比如说大名鼎鼎的 OmniCppComplete .这一类的插 ...
- 向输出到console的文字加样式
Chrome 控制台新玩法-向输出到console的文字加样式 有兴趣的同学可以文章最后的代码复制贴到控制台玩玩. Go for Code 在正常模式下,一般只能向console 控制台输出简单的 ...
- Window Service 计划任务
在ASP.NET中创建计划任务,就我个人而言,用过两种方式,一种是用SQL Server创建,把写好的SSIS包导入SQL Server创建的任务中,设置好时间让它去执行.还有一种就是利用window ...
- Servlet入门和ServletConfig、ServletContext
Servlet是一门用于开发动态web资源的技术. 若想开发一个动态web资源,需要完成以下2个步骤: 1)编写一个Java类,实现servlet接口: 2)把开发好的Java类部署到web服务器中. ...
- DateTimePicker.Text不靠谱
DateTimePicker.Text不靠谱 获取时:在DateTimePicker.ValueChanged事件中,获取到的Text有可能是string.Empty!!!,特别当ValueChang ...
- 深入浅出Mybatis-sql自动生成
本文提供了一种自动生成sql语句的方法,它针对的对象是有主键或唯一索引的单表,提供的操作有增.删.改.查4种.理解本文和本文的提供的代码需要有java注解的知识,因为本文是基于注解生成sql的.本文适 ...
- Android中检测软键盘的弹出和关闭
Android系统并没有提供明显的API来监听软键盘的弹出和关闭,但是在某些情况下我们还是有办法来检测软键盘的弹出和关闭. 从StackOverflow找到了一个不错的方法.但是这种只适用于在mani ...
- Markdown写作
What is markdown? Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown ...