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. 新手学习PHP的避雷针,这些坑在PHP开发中就别跳了

    不要!用记事本编辑php文件 早些年能用记事本编程是一些人自我吹嘘的资本,能用记事本编程就是牛逼的代名词.但是这里要告诫大家的是,千万不要使用Windows自带的记事本编辑任何文本文件.用Window ...

  2. [RedHat]“is not in the sudoers file”解决方法

    当在终端执行sudo命令时,系统提示“luckchengis not in the sudoers file”: $ sudo ls Password: luckcheng is not in the ...

  3. Win10 系统运行VsCode出现白屏的问题(亲测有效)

    Win10 系统运行VsCode出现白屏的问题(亲测有效) 新买的本本,昨天VScode运行还正常,今天打开一直白屏,什么都没有,只有几个小格格,也不是卡死的那种,可以轻松关闭, 刚开始以为版本问题, ...

  4. Tex 论文写作 jpg eps图像

    pdflatex只能支持pdf.jpg.jpeg.png共4中格式的图片.所以在插入eps图像是会没法显示,使用latex编译不存在这个问题,但是,我还不会用,编译完后从哪里看不知道. 这个里面说的详 ...

  5. linux nmon安装

    系统版本红帽7.7: [root@hostuser1 nmon_permon]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core ...

  6. pycharm pro与你同在

    下载激活码和激活依赖的jar包,地址(https://www.lanzous.com/b00t4aneb密码:67t9)按照步骤操作即可第一步:正确安装 Pycharm 软件(版本2019.1.3 p ...

  7. UltraEdit设置打开的文件类型,怎么打开大文本文件

    点击高级,配置,选择文件处理下的临时文件,设置如图即可打开超大文本文件. 补充:视图——显示行号.

  8. Permission denied 解决办法

    Permission denied 解决的办法: $ sudo chmod -R 777 某一目录 其中-R 是指级联应用到目录里的所有子目录和文件777 是所有用户都拥有最高权限

  9. Mysq的安装

    1.安装包下载 2.安装教程 (1)配置环境变量 (2)生成data文件 (3)安装MySQL (4)启动服务 (5)登录MySQL (6)查询用户密码 (7)设置修改用户密码 (8)退出 1.安装包 ...

  10. 一个超几何函数$_3F_2$的积分

    \[\Large\displaystyle \int_0^\infty{_3F_2}\left(\begin{array}c\dfrac58,\dfrac58,\dfrac98\\\dfrac12,\ ...