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对字符串的操作4之 字符串的格式化函数

    strtolower($str ) strtoupper($str ) 大小写转换 strtotime('2018-1-1 0:0') 字符串转时间戳 date('Y-m-d H:i:s',time( ...

  2. css动画 自动打字,让你的文字飞舞起来

    自动打字的效果 非一般的炫酷 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  3. linux下如何部署php项目?

    linux下部署php项目环境可以分为两种,一种使用Apache,php,mysql的压缩包安装,一种用yum命令进行安装. 使用三种软件的压缩包进行安装,需要手动配置三者之间的关系.apache和p ...

  4. 网页域名在QQ内被多人投诉举报拦截的解决方案

    背景 相信大家经常会遇到一个头疼的问题就是,明明自己的网页没有违规内容(比如线下活动的推广),但链接在QQ内转发分享会被QQ管家拦截,导致用户无法访问. 那么当大家遇到这个问题的时候应该怎么办呢?不用 ...

  5. c/c++学习01

    c++指针初始赋值: //指针初始赋值 int* a = new int(3); //第二种赋值 int 初始值 = 100; int *b = &初始值; //由new分配的内存块通常使用过 ...

  6. APP测试用例

    日程管理APP测试用例 测试编号 测试用例 实际结果 期望结果 测试结果(Pass/Failed) 备注 NO.1 输入正确的用户名和密码点击登录 登录成功 登录成功 Pass NO.2 点击注册界面 ...

  7. gcc 简单使用笔记

    编译生成可执行文件(bin文件): gcc test.c //默认生成可执行文件名为a.out 指定可执行文件名: gcc -o test test.c 编译生成目标文件(.o文件): gcc -c ...

  8. Linux - Shell - 字符串拼接

    概述 shell 的字符串拼接 1. 字符串声明 概述 字符串的基本操作 脚本 1 # 声明字符串 str01="str01" echo ${str01} # 单引号也可以 # 不 ...

  9. 京东秒杀抢购的小脚本和chorme的一个开发者插件

    chorme开发者插件 下载源码包:https://github.com/gongjunhao/seckill/archive/master.zip 解压:seckill-master.zip 打开c ...

  10. DFS(深度优先搜索)

    基本概念 深度优先搜索算法(Depth First Search,简称DFS):一种用于遍历或搜索树或图的算法. 沿着树的深度遍历树的节点,尽可能深的搜索树的分支.当节点v的所在边都己被探寻过或者在搜 ...