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

1002 A+B for Polynomials

时间:2018-11-26 22:03:26      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:for   eps   opened   code   using   name   main   img   out   

水题~

一开始没看到保留一位小数,wa了一发,难受。

技术分享图片
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <string>
#include <cstdio>
#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 k,n;
int b[maxn];
double x;
double a[maxn];
int main()
{
    memset(a,0,sizeof(a));
    int maxx=0;
    cin>>k;
    for(int i=0;i<k;i++)
    {
        cin>>n>>x;
        a[n]=x;
        if(n>maxx)
            maxx=n;
    }
    cin>>k;
    for(int i=0;i<k;i++)
    {
        cin>>n>>x;
        a[n]+=x;
        if(n>maxx)
            maxx=n;
    }
    int ans=0;
    for(int i=maxx;i>=0;i--)
    {
        if(a[i])
        {
            b[ans]=i;
            ans++;
        }
    }
    cout<<ans;
    for(int i=0;i<ans;i++)
    {
        printf(" %d %.1lf",b[i],a[b[i]]);
    }
    cout<<endl;
    return 0;
}
View Code

 

1002 A+B for Polynomials

标签:for   eps   opened   code   using   name   main   img   out   

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

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