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. LED Decorative Light Manufacturer - LED Neon Rope: 5 Advantages

    In the past 100 years, lighting has come a long way. Nowadays, the decorative LED lighting design ca ...

  2. Eqaulize Prices

    There are n products in the shop. The price of the ii-th product is aiai. The owner of the shop want ...

  3. 为什么hadoop中用到的序列化不是java的serilaziable接口去序列化而是使用Writable序列化框架

    继上一个模块之后,此次分析的内容是来到了Hadoop IO相关的模块了,IO系统的模块可谓是一个比较大的模块,在Hadoop Common中的io,主要包括2个大的子模块构成,1个是以Writable ...

  4. 出现 HTTP Status 500 - Servlet.init() for servlet springmvc threw exception 异常

    出现这种异常在网上搜了搜 ,大多数都是说jdk和tomcat版本的问题:而我前几天都是运行得好好的,今天就编写了代码一运行项目发现报了这个错误.后台仔细看了看错误信息.结果是在你的项目中有相同的req ...

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

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

  6. Git提交时提示“Please make sure you have the correct access rights and the repository exists.”的解决方法

    1.首先打开Git Bash设置名字和邮箱: git config --global user.name "你的名字" git config --global user.email ...

  7. Springboot的多环境配置

    通常应用都会被安装到几个不同的环境(比如开发.测试.生产等),每个环境都会有一些参数是不一样的. Spring Boot对此也提供了支持,配置文件的名称只要满足application-{profile ...

  8. CSS学习(5)更多的选择器

    1.通配符选择器 * 表示选中所有元素 *{color:red;} 2.属性选择器  根据属性名和属性值选中元素 https://developer.mozilla.org/zh-CN/docs/We ...

  9. java spring-boot 服务器启动参数设置

    java -jar -Xms5866m -Xmx5866m -Xss256k -Xloggc:/home/work/spring-boot/logs/gc-%t.log -XX:+UseGCLogFi ...

  10. Java编写POST请求

    package com.mytesting; import java.io.DataOutputStream; import java.io.InputStream; import java.net. ...