码迷,mamicode.com
首页 > 其他好文 > 详细

1009 Product of Polynomials

时间:2018-12-03 14:05:02      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:sizeof   span   eof   bsp   rod   mem   main   ble   opened   

和之前多项式求和类似,注意筛0和输出即可。水题~

技术分享图片
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#define maxn 1005
#define INF 0x3f3f3f3f
#define EPS 1e-6
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
int n,m,x;
double y;
double a[2005],b[2005];
int c[maxn];
int main()
{
    memset(b,0,sizeof(b));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        c[i]=x;
        a[x]=y;
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        for(int j=0;j<n;j++)
        {
            double t1=y*a[c[j]];
            int t2=x+c[j];
            b[t2]+=t1;
        }
    }
    int p=0;
    for(int i=2005;i>=0;i--)
    {
        if(b[i]!=0)
            p++;
    }
    cout<<p;
    for(int i=2005;i>=0;i--)
    {
        if(b[i]!=0)
            printf(" %d %.1lf",i,b[i]);
    }
    cout<<endl;
}
View Code

 

1009 Product of Polynomials

标签:sizeof   span   eof   bsp   rod   mem   main   ble   opened   

原文地址:https://www.cnblogs.com/FTA-Macro/p/10057851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!