PAT:1009. Product of Polynomials (25) AC

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//【warning】double 输入%lf,输出%f
struct arr
{
  int exp;      //指数
  double cof;      //系数
}arr[1005];
double ans[2010];    //下标是指数,内容是系数
int main()
{
  memset(arr,0,sizeof(arr));
  memset(ans,0,sizeof(ans));
  int n,m;
  scanf("%d",&n);          //第一个多项式n项
  for(int i=0 ; i<n ; ++i)
  {
    scanf("%d %lf",&arr[i].exp,&arr[i].cof);
  }
  scanf("%d",&m);
  for(int i=0 ; i<m ; ++i)
  {
    int exp;          //第二个多项式指数
    double cof;          //第二个多项式系数
    scanf("%d %lf",&exp,&cof);
    for(int j=0 ; j<n ; ++j)
    {
      ans[exp+arr[j].exp]+=cof*arr[j].cof;    //指数相加,系数相乘,存入相应指数的系数数组中
    }
  }
  int num=0;
  for(int i=0 ; i<2010 ; ++i)        //统计项数
    if(ans[i]!=0)
      ++num;
  printf("%d",num);
  for(int i=2009 ; i>=0 ; --i)      //【warning】ans数组2010个元素,下标最多到2009
  {
    if(ans[i]!=0)
    {
      printf(" %d %.1f",i,ans[i]);
    }
  }
  //system("pause");
  return 0;
}
时间: 2024-08-10 02:06:40

PAT:1009. Product of Polynomials (25) AC的相关文章

[PTA] PAT(A) 1009 Product of Polynomials (25 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Result Problem portal:1009 Product of Polynomials Description Input Output Sample Sample Input Sample Output Solution Analysis Code #include <bits/stdc++.h>

PAT Advanced 1009 Product of Polynomials (25分)

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 N?1?? a?N?1???? N?2?? a?N?2?

1009. Product of Polynomials (25)——PAT (Advanced Level) Practise

题目信息: 1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 c

PAT 1009. Product of Polynomials (25)

1009. Product of Polynomials (25) 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 polynomi

1009 Product of Polynomials (25)(25 分)

1009 Product of Polynomials (25)(25 分) 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 pol

1009 Product of Polynomials (25分) 多项式乘法

1009 Product of Polynomials (25分) 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 polynomi

PAT (Advanced Level) 1009. Product of Polynomials (25)

简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; double a[3000],b[3000],c[3000]; int k; int main() { for(int i=0;i<=2000;i++) a[i]=b[i]=c[i]=0; int Max=-1

PAT甲题题解-1009. Product of Polynomials (25)-多项式相乘

多项式相乘 注意相乘结果的多项式要开两倍的大小!!! #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <string.h> using namespace std; //两个多项式相乘 const int maxn=1000+5; int k; //原本定义个exp导致编译错误,没想到定义成exp1.exp2也会编译错误,

1009 Product of Polynomials (25)(25 point(s))

problem 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 a~N1~ N2 a~N2~ ..