题目链接:https://pintia.cn/problem-sets/1108548596745592832/problems/1108548661014913033

题目大意:

这仍然是一道关于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,故不输出。

具体思路:模拟多项式除法,注意精度控制。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 1e5+;
double a[maxn],b[maxn],c[maxn];
int main()
{
int n,m,tmp,maxa,maxb;
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d",&tmp);
scanf("%lf",&a[tmp]);
if(i==)
maxa=tmp;
}
scanf("%d",&m);
for(int i=; i<m; i++)
{
scanf("%d",&tmp);
scanf("%lf",&b[tmp]);
if(i==)
maxb=tmp;
}
int j;
for(int i=maxa; i>=maxb; i--)
{
c[i-maxb]=a[i]/b[maxb];
for( j=maxb; j>=; j--)
{
a[i+j-maxb]-=b[j]*c[i-maxb];
}
}
int num1=,num2=;
for(int i=maxa-maxb; i>=; i--)
{
if(fabs(c[i])>1e-)
{
if(fabs(c[i])<0.05)
c[i]=;
else
num1++;
}
}
if(num1==)
{
printf("0 0 0.0\n");
}
else
{
printf("%d",num1);
for(int i=maxa-maxb; i>=; i--)
{
if(fabs(c[i])>1e-)
printf(" %d %.1lf",i,c[i]);
}
printf("\n");
}
for(int i=maxb-; i>=; i--)
{
if(fabs(a[i])>1e-)
{
// cout<<a[i]<<endl;
if(fabs(a[i])<0.05)
a[i]=;
else
num2++;
}
}
if(num2==)
{
printf("0 0 0.0\n");
}
else
{
printf("%d",num2);
for(int i=maxb-; i>=; i--)
{
if(fabs(a[i])>1e-)
printf(" %d %.1lf",i,a[i]);
}
printf("\n");
}
}

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

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

    7-10 多项式A除以B (25分)   这仍然是一道关于A/B的题,只不过A和B都换成了多项式.你需要计算两个多项式相除的商Q和余R,其中R的阶数必须小于B的阶数. 输入格式: 输入分两行,每行给出 ...

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

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

  3. 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 ...

  4. 多项式A除以B

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

  5. 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 ...

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

  10. PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)

    1145 Hashing - Average Search Time (25 分)   The task of this problem is simple: insert a sequence of ...

随机推荐

  1. POJ 1971 Parallelogram Counting (Hash)

          Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6895   Acc ...

  2. WPF开发的界面调用C++生成的dll文件

    以引用d1.dll为例. [生成d1.dll] 文件——新建——项目——Visual C++——Win32项目,选择DLL,点击Finish.在d1.cpp中添加代码 #include "s ...

  3. go操作redis和mysql示例

    一:redis示例 使用redis的包是: github.com/garyburd/redigo/redis 1:编写第一个示例: 链接,设置,获取 redis_basic.go package ma ...

  4. 3D转换(位置)+过渡+透视

    效果如图: html代码: <div class="door"> <div class="in"><div> </di ...

  5. Dream team: Stacking for combining classifiers梦之队:组合分类器

     sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  6. Tensorflow object detection API 搭建物体识别模型(三)

    三.模型训练 1)错误一: 在桌面的目标检测文件夹中打开cmd,即在路径中输入cmd后按Enter键运行.在cmd中运行命令: python /your_path/models-master/rese ...

  7. Linux shell 自动删除n天前日志

    linux是一个很能自动产生文件的系统,日志.邮件.备份等.虽然现在硬盘廉价,我们可以有很多硬盘空间供这些文件浪费,让系统定时清理一些不需要的文件很有一种爽快的事情.不用你去每天惦记着是否需要清理日志 ...

  8. UNIX网络编程中的字节序问题

    1.inet_pton 函数原型: inet_pton:将“点分十进制” -> “二进制整数” int inet_pton(int af, const char *src, void *dst) ...

  9. bootstrap 在线设计工具layout IT

    Layoutit! bootstrap 可视化布局BETA

  10. Spring Boot 2下使用Feign找不到@EnableFeignClients的解决办法

    最近在实践Spring Boot 2+Spring Cloud(Finchley.M9),在用到Feign的时候发现@EnableFeignClients注解开不了,独立使用Feign是可以的,但就是 ...