首页 > 其他分享 >1002 A+B for Polynomials (附测试点3456的坑)

1002 A+B for Polynomials (附测试点3456的坑)

时间:2022-11-30 21:35:54浏览次数:43  
标签:3456 测试点 ++ Polynomials int 3.2 each include 1002

题目:1002 A+B for Polynomials

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 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、使用map

2、注意当底数为0的项不需要输出,当两个多项式相加结果为0时,直接输出0就好了。

测试样例:

1 0 3.2 
1 0 -3.2

 输出:

0

 

代码:

#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<map>
using namespace std;
int main(){
    map<int, double> m;
    map<int, double>::reverse_iterator it;
    int k = 2,n,e,count = 0;
    double c;
    for(int i = 0; i < k; i++){
        cin>>n;
        for(int j = 0; j < n; j++){
            cin>>e>>c;
            m[e] += c;
        }
    }
    for(it = m.rbegin(); it != m.rend(); it++){
        if(it->second == 0){
            continue;
        }
        count++;
    }
    cout<<count;
    for(it = m.rbegin(); it != m.rend(); it++){
        if(it->second == 0){
            continue;
        }
        cout<<" "<<it->first<<" ";
        cout<<fixed<<setprecision(1)<<it->second;
    }
    return 0;
}

 

标签:3456,测试点,++,Polynomials,int,3.2,each,include,1002
From: https://www.cnblogs.com/yccy/p/16939812.html

相关文章

  • 1234567
    后台代码:1.easyopen字样全部改成dataServer,其余功能不变前台代码:1.服务端,管理端登录页面改造2.管理端管理页面改造2022103120.50demo03后台代码改造成功,待测......
  • 1002. A+B for Polynomials (25)
    1002.A+BforPolynomials(25)时间限制400ms内存限制65536kB代码长度限制16000B判题程序......
  • 【221123-7】计算(2-根号3)的1002次方乘以(7+4倍根号3)的501次方
    ......
  • P1002 过河卒 详细题解 搜索回溯+递归 [NOIP2002 普及组]
    题目描述棋盘上A点有一个过河卒,需要走到目标B点。卒行走的规则:可以向下、或者向右。同时在棋盘上C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方......
  • 肖sir___车载测试___测试点归纳
     一、语音测试点:=======================================================语⾳测试⽤例测试语⾳的输⼊,主要包括以下⼏个⽅⾯:①语⾳输⼊离拾⾳设备的距离:近距离、远......
  • PAT乙级 —— 1002 数字分类 (20)
    题目链接:​​数字分类(20)​​题目描述给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:A1=能被5整除的数字中所有偶数的和;A2=将被5除后余1的数字按给出顺......
  • 物联网设备测试点
    运动控制子系统测试范围?接受人机交互命令,机器人实时控制机器人各部位包括表情,测试包括系统系统各个板子(RC,RB)状态测试(工作,休眠,充电,升级,工厂模式),动作管理测试,传感器测试,表......
  • 洛谷 P1002 [NOIP2002 普及组] 过河卒
    第一个dp(动态规划)题纪念一下先尝试暴力写一个递归,由于x与y只能增加,不存在回路。#include<iostream>usingnamespacestd;inta_x,a_y,h_x,h_y,sum=0;//a_x,a_y代表目标地......
  • 611002 CAD 选项设置草图设置
    本节课讲解2CAD选项设置草图设置。1.选项设置快捷键【OP】,在英文输入法的状态下,点击【空格】会跳出对话框。2.【文件】中有【自动保存文件位置】和【样板设置】,点击加......
  • PAT1002
    //10的100次方一共101位数#include<stdio.h>intmain(){intindexNum=0;intsum=0;charnum[101]={0};charresult[10]={0};intindexResult=0;int......