[patl2-018]多项式A除以B
2024-09-05 01:50:37
解题关键:多项式除法的模拟。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iostream>//解法有些问题,应该用链表解,因为题目数据是整形范围
#include<cmath>
#define maxn 1000006
using namespace std;
typedef long long ll;
int maxa=-,maxb=-;
double a[maxn],b[maxn],c[maxn];
int clearzero(double *a,int ma){
int cnt=;
for(int i=ma;i>=;i--){
if(fabs(a[i])>=0.05) cnt++;
}
return cnt;
}
void output(int cnt,double *a,int ma){
if(cnt==){
printf("0 0 0.0");
}else{
printf("%d",cnt);
for(int i=ma;i>=;i--){
if(fabs(a[i])>=0.05) printf(" %d %.1lf",i,a[i]);
}
}
}
int main(){
int n,m,t1;
double t2;
cin>>n;
for(int i=;i<n;i++){
cin>>t1>>t2;
a[t1]=t2;
maxa=max(maxa,t1);
}
cin>>m;
for(int i=;i<m;i++){
cin>>t1>>t2;
b[t1]=t2;
maxb=max(maxb,t1);
}
for(int i=maxa;i>=maxb;i--){
c[i-maxb]=a[i]/b[maxb];
for(int j=maxb;j>=;j--){
a[j+i-maxb]-=c[i-maxb]*b[j];
}
} int cnt1,cnt2;
cnt1=clearzero(c,maxa-maxb);//商
cnt2=clearzero(a,maxb);//余数 output(cnt1,c,maxa-maxb);
printf("\n");
output(cnt2,a,maxb); return ;
}
最新文章
- Warning: strftime(): It is not safe to rely on the system&#39;s timezone settings.
- mysql 数据库连接超时的问题 autoReconnect=true
- JSTL标签库
- MFC 中控件的启用与禁用
- NHibernate分页
- C# 中 datagridview 绑定BindingList类型和更新
- CentOS忘记root密码的解决方法
- Python入门 学习笔记 (一)
- 利用boost做string到wstring转换,以及字符集转换 - Error - C++博客
- ORA-31626:作业不存在 ORA-31633:无法创建主表";XXX.SYS_IMPORT_FULL_05";
- dephi中单击鼠标拖动窗口(使用WM_SYSCOMMAND)
- Spring Boot属性文件配置文档(全部)
- JDK设计模式之——责任链(Filter)
- Javascript数组系列三之迭代方法2
- 解决Oracle登录极慢的问题
- [luogu4201][bzoj1063]设计路线【树形DP】
- 在 Python 中使用 in_memory 工作空间
- [iOS] UICollectionView实现图片水平滚动
- 在AbpZero中hangfire后台作业的使用——开启hangfire
- Cardano(ADA), EOS, RChain(RHOC), Aeternity(AE) 都是极其好的币