• A1002. A+B for Polynomials (25)


    This time, you are supposed to find A+B where A and B are two polynomials.

    Input

    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

    For each test case you should output the sum 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 to 1 decimal place.

    Sample Input

    2 1 2.4 0 3.2
    2 2 1.5 1 0.5
    

    Sample Output

    3 2 1.5 1 2.9 0 3.2
     1 // hahaha.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include <stdafx.h>
     5 #include <stdio.h>
     6 #include <iostream>
     7 #include <vector>
     8 #include <map>
     9 #include <string>
    10 #include <cstdio>
    11 #include <set>
    12 #include <algorithm>
    13 #include <string.h>
    14 using namespace std;
    15 const int maxn=1020;
    16 double p[maxn]={0};
    17 
    18 int main()
    19 {
    20     int k,n;
    21     double a;
    22     scanf("%d",&k);
    23     for(int i=0;i<k;i++)
    24         {
    25         scanf("%d %lf",&n,&a);
    26         p[n]+=a;
    27         }
    28     scanf("%d",&k);
    29     for(int i=0;i<k;i++)
    30         {
    31         scanf("%d %lf",&n,&a);
    32         p[n]+=a;
    33         }
    34     int count=0;
    35     for(int i=0;i<maxn;i++)
    36         {
    37         if(p[i]!=0)count++;
    38         }
    39     printf("%d",count);
    40     for(int i=maxn-1;i>=0;i--)
    41         {
    42         if(p[i]!=0)printf(" %d %.1f",i,p[i]);
    43         }
    44     return 0;
    45 }
  • 相关阅读:
    MFC中CDialog与其对话框资源的绑定 dll中资源的切换
    DirectDraw 显示 YUV
    ClipCursor与GetClipCursor 用法
    MFC消息处理流程概述 .
    HTML5 WebSocket 技术介绍
    NodepartySZ1 深圳聚会活动回顾总结[2012.01.08] CNode
    index QuickWeb文档
    Node.js Manual
    An innovative way to replace AJAX and JSONP using node.js and socket.io
    RequireJS
  • 原文地址:https://www.cnblogs.com/ligen/p/4341508.html
Copyright © 2020-2023  润新知