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. AWS ec2的ubuntu14.04上安装git服务

    http://imerc.xyz/2015/11/13/Ubuntu-14-04%E4%B8%8AGit%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E6%90%AD%E5 ...

  2. DB技能数据库里把技能伤害调整

    1. MagID 技能代号 2. MagName 技能名称 3. Effect Type 效果类型(使用技能时角色的动作效果) 4. Effect 效果(技能产生的动画效果) 5. Spell 每次耗 ...

  3. python学习之 logging包

    1,logging包 python的一个包,专门用来写日志的. 官方一共划分了6个等级的log类型,分别对应重要性等级50,40,30,20,10,0: 级别排序:CRITICAL > ERRO ...

  4. 【做题笔记】P1330 封锁阳光大学

    读题易得:对于有边的两个点 \(u,v\) ,能且仅能其中一点对这条边进行封锁. 什么意思呢?假设给这张图上的点进行染色,那么对于上述的两个点 \(u,v\) ,\(u,v\) 必须异色(理解这一点很 ...

  5. .net core各种修改环境变量的方式

    除了修改系统变量,或者程序硬编码中修改,还有以下方法: 发布在IIS中,修改web.config <environmentVariables> <environmentVariabl ...

  6. 第二十九篇 玩转数据结构——线段树(Segment Tree)

          1.. 线段树引入 线段树也称为区间树 为什么要使用线段树:对于某些问题,我们只关心区间(线段) 经典的线段树问题:区间染色,有一面长度为n的墙,每次选择一段墙进行染色(染色允许覆盖),问 ...

  7. Mongodb学习笔记(三)性能篇

    一.索引管理 MongoDB提供了多样性的索引支持,索引信息被保存在system.indexes中MongoDB中_id字段在创建的时候,默认已经建立了索引,这个索引比较特殊,并且不可以删除,不过Ca ...

  8. vue去掉地址栏# 方法

    超简单 export default new Router({ //将mode 设置为‘history‘ 即可.默认情况是’hash’ 所以会有丑陋的# mode: 'history', routes ...

  9. oracle中以dba_、user_、v$_、all_、session_、index_开头

    原 oracle中以dba_.user_.v$_.all_.session_.index_开头 2011年07月05日 11:26:06 clbxp 阅读数:3279   oracle中以dba_.u ...

  10. Cosmetic Airless Bottles To Meet Practical Requirements

    Today, people use cosmetic bottles, many of which are in cosmetic airless bottles. We can use them, ...