PAT甲级1009 多项式乘法(简单模拟)

题目链接:传送门

多项式乘法,简单模拟跟之前多项式加法异曲同工,只要你英文够好看得出是多项式基本就没得问题。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#define inf 4000000000000000000
using namespace std;
typedef long long ll;
const ll maxn=1e6+50;
const ll mod=1e9+7;
const double eps=1e-9;
struct node
{
	ll x;
	double y;
}a[maxn],b[maxn];
double c[maxn];
int main()
{
	ll n,m;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		ll y;
		double x;
		scanf("%lld %lf",&a[i].x,&a[i].y);
	}
	
	scanf("%lld",&m);
	for(ll i=1;i<=m;i++)
	{
		ll y;
		double x;
		scanf("%lld %lf",&b[i].x,&b[i].y);
	}
	
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			ll zhishu=a[i].x+b[j].x;
			double xishu=a[i].y*b[j].y;
			c[zhishu]+=xishu;
		}
	}
	ll ct=0;
	for(ll i=2000;i>=0;i--)
	{
		if(c[i]!=0.0)ct++;
	}
	printf("%lld",ct);
	for(ll i=2000;i>=0;i--)
	{
		if(c[i]!=0.0)printf(" %lld %.1lf",i,c[i]);
	}
	putchar(10);
	//scanf("%lld",&n);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值