题意:给你A,B两个多项式,问你A/B的值;注意多项式给你的是每个式子的指数与系数;保留到一位小数,如果出现系数为0(保留后也是)的情况,请不要输出它,如果没有非系数为0的情况就输出特殊

题解:多项式类似于“a*x^4+b*x^3+c*x^2+d*x^1+e*x^0”的形式,两个多项式除法就是模拟除法做

   现在被除数最大指数的系数、被 除数最大指数的系数除以、结果就是商的系数,两个指数的差就是商的指数

   然后枚举除数每一位乘以这个值来被 被除数减去,最后找被除数后一个位置继续循环,直到被除数最大项大于除数最大项

   最后有一个点需要注意,因为需要的是保留答案后系数为0也不能输出,所以在保留答案是一定要判断是否为0,不能再最后输出时在判断

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1E-1
#define Eps 1E-1
/*注意可能会有输出-0.000*/
#define sgn(x) (x<-Eps? -1 :x<Eps? 0:1)//x为两个浮点数差的比较,注意返回整型
#define cvs(x) (x > 0.0 ? x+eps : x-eps)//浮点数转化
#define zero(x) (((x)>0?(x):-(x))<eps)//判断是否等于0
#define mul(a,b) (a<<b)
#define dir(a,b) (a>>b)
typedef long long ll;
typedef unsigned long long ull;
const int Inf=<<;
const ll INF=1LL<<;
const double Pi=acos(-1.0);
const int Mod=1e9+;
const int Max=;
double divide[Max],divisor[Max];//被除数 除数
double business[Max],remainde[Max];//商 余数
int busindex[Max],remindex[Max];//答案系数
int coundiv,counsor;
void Print(int coun,int* ansindex,double* ans)
{
if(!coun)
printf("0 0 0.0\n");
else
{
printf("%d",coun);
for(int i=;i<coun;++i)
{
if(!zero(ans[i]))
printf(" %d %.1f",ansindex[i],ans[i]);
}
printf("\n");
}
return;
}
void Divison(int n,int dif,double num)
{
for(int i=n;i>=dif;--i)
{
divide[i]-=divisor[i-dif]*num;
}
return;
}
void Solve(int maxdiv,int maxsor)
{
coundiv=counsor=;
for(int i=maxdiv;i>=maxsor;--i)
{
busindex[coundiv]=i-maxsor;
int dif=busindex[coundiv];
business[coundiv]=divide[i]/divisor[maxsor];
Divison(i,dif,business[coundiv]);
business[coundiv]=business[coundiv];
if(sgn(business[coundiv])!=)//注意
coundiv++;
}
for(int i=maxsor-;i>=;--i)
{
remindex[counsor]=i;
remainde[counsor]=divide[i];
if(sgn(remainde[counsor])!=)
counsor++;
}
return;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(divide,,sizeof(divide));
memset(divisor,,sizeof(divisor));
int maxdiv=,maxsor=;
int index;
for(int i=;i<n;++i)
{
scanf("%d",&index);
maxdiv=max(maxdiv,index);
scanf("%lf",&divide[index]);
}
scanf("%d",&n);
for(int i=;i<n;++i)
{
scanf("%d",&index);
maxsor=max(maxsor,index);
scanf("%lf",&divisor[index]);
}
Solve(maxdiv,maxsor);
Print(coundiv,busindex,business);
Print(counsor,remindex,remainde);
}
return ;
}

团体程序设计天梯赛 L2-018. 多项式A除以B(模拟)的更多相关文章

  1. 团体程序设计天梯赛-练习集-L1-037. A除以B

    L1-037. A除以B 真的是简单题哈 —— 给定两个绝对值不超过100的整数A和B,要求你按照“A/B=商”的格式输出结果. 输入格式: 输入在第一行给出两个整数A和B(-100 <= A, ...

  2. 团体程序设计天梯赛(CCCC) L3009 长城 方法证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  3. 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  4. 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  5. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  6. 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  7. 团体程序设计天梯赛(CCCC) L3013 非常弹的球 不同思路

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  8. 团体程序设计天梯赛(CCCC) L3012 水果忍者 上凸或下凹的证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  9. 树状数组+二分答案查询第k大的数 (团体程序设计天梯赛 L3-002. 堆栈)

    前提是数的范围较小 1 数据范围:O(n) 2 查第k大的数i:log(n)(树状数组查询小于等于i的数目)*log(n)(二分找到i) 3 添加:log(n) (树状数组) 4 删除:log(n) ...

  10. PTA L2-001 紧急救援-最短路(Dijkstra)多条最短路找最优解并输出路径 团体程序设计天梯赛-练习集

    L2-001 紧急救援 (25 分)   作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快 ...

随机推荐

  1. jpa单向一对多关联映射

    如果在一的@OneToMany有@manyToOne则是双向一对多关联,如果在多的那面没有@manyToOne关联则是单向一对多关联 class和student是一对多的关系 表结构 student ...

  2. 关于Z序的总结

    //转自:http://blog.csdn.net/flowshell/article/details/4797917 Z 序:一个重叠窗口的堆,每个窗口在Z 序中 都有唯一一个位置.一个窗口的Z 序 ...

  3. python之django直接执行sql语句

    python之django直接执行sql语句 sql = 'select * from stu' info = 模型类.objects.raw(sql)

  4. 客户也可以申请它使用的最后一个IP地址。如果该客户所在的网络中此IP仍然可用,服务器就可以准许该申请。

    http://baike.baidu.com/item/IP地址 公有地址 公有地址(Public address)由Inter NIC(Internet Network Information Ce ...

  5. jq封装选项卡写法

    jq普通选项卡写法: var tabTag=$('#tabon'); var tabon=tabTag.find('li');//菜单栏 var tabCon=$(".hidden" ...

  6. 模块 - time/datetime

    time 模块 time模块方法: >>> import time >>> time.time() #时间戳 秒级别 1519212085.6211221 #从19 ...

  7. tomcat和jboss的区别

    1. Tomcat是Apache鼎力支持的Java Web应用服务器(注:servlet容器),由于它优秀的稳定性以及丰富的文档资料,广泛的使用人群,从而在开源领域受到最广泛的青睐. 2. Jboss ...

  8. unity 里调试native code

    因项目需要,需要调试dll工程代码. 把生成的debug dll和pdb拷贝进unity的plugins工程,遇到 断点无法进入,修改下调试信息格式,OK.

  9. Dictionary里使用struct,enum做key

    首先看下Dictionary的源码 public void Add (TKey key, TValue value) { if (key == null) throw new ArgumentNull ...

  10. Tomcat Server

    Tomcat Server的组成部分: 站在框架的顶层的是Server和ServiceServer:servletcontainer Service:Service是这样一个集合:它由一个或者多个Co ...