7-10 多项式A除以B (25分)
 

这仍然是一道关于A/B的题,只不过A和B都换成了多项式。你需要计算两个多项式相除的商Q和余R,其中R的阶数必须小于B的阶数。

输入格式:

输入分两行,每行给出一个非零多项式,先给出A,再给出B。每行的格式如下:

N e[1] c[1] ... e[N] c[N]
 

其中N是该多项式非零项的个数,e[i]是第i个非零项的指数,c[i]是第i个非零项的系数。各项按照指数递减的顺序给出,保证所有指数是各不相同的非负整数,所有系数是非零整数,所有整数在整型范围内。

输出格式:

分两行先后输出商和余,输出格式与输入格式相同,输出的系数保留小数点后1位。同行数字间以1个空格分隔,行首尾不得有多余空格。注意:零多项式是一个特殊多项式,对应输出为0 0 0.0。但非零多项式不能输出零系数(包括舍入后为0.0)的项。在样例中,余多项式其实有常数项-1/27,但因其舍入后为0.0,故不输出。

输入样例:

4 4 1 2 -3 1 -1 0 -1
3 2 3 1 -2 0 1
 

输出样例:

3 2 0.3 1 0.2 0 -1.0
1 1 -3.1
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int,int> pll;
const int maxn= 2e5+;
const int mod =1e9+;
const double EPS = 1e-;
/*bool cmp()
{ }*/ double a1[maxn],a2[maxn],a3[maxn];
//a1为同时为被除数和余数,a2为除数,a3为商
void solve(double a[],int maxx)
{
int no=;
for(int i=maxx;i>=;i--)
{
if(abs(a[i])+0.05>=0.1)
no++;
}
if(no==) cout << "0 0 0.0" << endl;
else
{
cout << no ;
for(int i=maxx;i>=;i--)
{
if(abs(a[i])+0.05>=0.1)
printf(" %d %.1f",i,a[i]);
}
cout <<endl;
}
} int main()
{
/* ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);*/
int n;
cin >>n;
int maxnum1=-,maxnum2=-;
for(int i=;i<=n;i++)
{
int x;
cin >> x;
cin >> a1[x];
maxnum1=max(maxnum1,x);
}
int m;
cin >> m;
for(int i=;i<=m;i++)
{
int x;
cin >> x;
cin >> a2[x];
maxnum2=max(maxnum2,x);
}
int cnt1=maxnum1,cnt2=maxnum2;
while(cnt1>=cnt2)
{
double num=a1[cnt1]/a2[cnt2];
a3[cnt1-cnt2]=num;
for(int i=cnt1,j=cnt2;j>=;i--,j--)
{
a1[i]-=a2[j]*num;
}
while(abs(a1[cnt1])<0.001) cnt1--;
}
//cout << 6666 <<endl;
solve(a3,maxnum1-maxnum2);
solve(a1,maxnum1);
return ;
}

7-10 多项式A除以B (25分)(多项式除法)的更多相关文章

  1. 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 po ...

  2. 9.9递归和动态规划(八)——给定数量不限的硬币,币值为25分,10分,5分,1分,计算n分有几种表示法

    /**  * 功能:给定数量不限的硬币.币值为25分,10分.5分.1分,计算n分有几种表示法. */ public static int makeChange(int n){ return make ...

  3. 多项式A除以B

    这个问题我是在PAT大区赛题里遇见的.题目如下: 多项式A除以B(25 分) 这仍然是一道关于A/B的题,只不过A和B都换成了多项式.你需要计算两个多项式相除的商Q和余R,其中R的阶数必须小于B的阶数 ...

  4. 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 pol ...

  5. (转载) 天梯赛 L2-018. 多项式A除以B

    题目链接 题目描述 这仍然是一道关于A/B的题,只不过A和B都换成了多项式.你需要计算两个多项式相除的商Q和余R,其中R的阶数必须小于B的阶数. 输入格式: 输入分两行,每行给出一个非零多项式,先给出 ...

  6. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  7. PAT甲级 1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  8. A1082 Read Number in Chinese (25)(25 分)

    A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are suppose ...

  9. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

随机推荐

  1. SparkSQL个人记录

    SparkSQL将RDD封装成一个DataFrame对象,这个对象类似于关系型数据库中的表. 一.SparkSQL入门 1.创建DataFrame 相当于数据库中的一张表,它是一个只读的表,不能在运算 ...

  2. 计算几何-Line-Left-Intersect

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 好好领悟一下ve ...

  3. python evel()的用法

    老生常谈部分: eval(expression[, globals[, locals]]) expression -- 表达式. globals -- 变量作用域,全局命名空间,如果被提供,则必须是一 ...

  4. vue项目怎么搭建到云服务器上

    链接1:https://blog.csdn.net/qq_37741554/article/details/87560823 linux下载安装node.js 链接2:https://blog.csd ...

  5. Catalyst9K设备介绍

    Catalyst9K系列的里面包含了多款交换机,以及无线控制器,甚至包含了无线AP,如下将简单的介绍这几款产品的情况: 首先,这是一种总体的对应关系: 1.Catalyst9200 Series 主要 ...

  6. 前端——语言——Core JS——《The good part》读书笔记——第五章节(Inheritance)

    本章题目是继承,实质上介绍JS如何实现面向对象的三大特性,封装,继承,多态.本章的最后一个小节介绍事件. 与Java语言对比,虽然名称同样称为类,对象,但是显然它们的含义存在一些细微的差异,而且实现三 ...

  7. 联合查询:union

    1.联合查询:union 1.1 作用:将多条select语句的结果,合并到一起,称之为联合操作. 1.2 语法:( ) union ( ); 例子:(select name from info_or ...

  8. 从TCL欲成JDI股东看,面板行业进入“群架”时代

    当下,屏幕早已成为第一入口.PC.智能手机.平板电脑.电视.家庭智能终端.智慧交通.智能穿戴设备.汽车中控大屏--种种设备都是以屏幕为最重要的视觉呈现方式,让人们在一个个奇幻世界中畅游.也正是因为屏幕 ...

  9. Eclipse导入git上的maven web项目 以及部署成功运行

      在公司开发的时候都是用maven 以及git环境 开发的环境,那么我们初学者怎么将公司的项目成功导入到eclipse中,并且成功运行那???下面的教程就可以告诉大家~ (ps:第二步可能是大家会遇 ...

  10. dbGet(三)

    inst flat design下的instance Parent Object group, hInst, instTerm, io, pBlkg, ptn, rBlkg, sdp, topCell ...