模拟多项式除法,其实挺简单的,不要被吓怕了



typedef pair<int,double> P;
const int maxn = 1e5+10;
double a[maxn],b[maxn];
double c[maxn],d[maxn];
int main(void)
{
	int n,m;cin>>n;
	int maxn1 = 0,maxn2= 0;
	rep(i,0,n){
		int e;double f;
		cin>>e>>f;
		a[e] = f;
		maxn1 = max(maxn1,e);
	}    
	cin>>m;
	rep(i,0,m){
		int e;double f;
		cin>>e>>f;
		b[e] = f;
		maxn2 = max(maxn2,e);
	}
	// cout<<maxn1<< " "<<maxn2<<endl;
	for(int i = maxn1;i >= maxn2;--i){
		// if(a[i] == 0.0) continue;
		double t = a[i]/b[maxn2];
		// cout<<t<<endl;
		c[i-maxn2] = t;
		int k = 0;
		for(int j = maxn2; j >= 0; --j,++k){
			a[i-k] -= t*b[j];
		}
	}
	// DEBUG;
	// map<int,double> ma1;
	vector<P> vec;
	for(int i = maxn1-maxn2; i >= 0; --i)
		if(fabs(c[i]) >= 0.05)
			vec.push_back(P(i,c[i]));
	int len = vec.size();
	if(len == 0)
		puts("0 0 0.0");
	else{
		printf("%d ",len);
		for(int i = 0;i < len; ++i)
			printf("%d %.1f%c",vec[i].first,vec[i].second," \n"[i==len-1]);
	}
	vec.clear();
	for(int i = maxn2-1; i >= 0; --i)
		if(fabs(a[i]) >= 0.05)
			vec.push_back(P(i,a[i]));
	len = vec.size();
	if(len == 0)
		puts("0 0 0.0");
	else{
		printf("%d ",len);
		for(int i = 0;i < len; ++i)
			printf("%d %.1f%c",vec[i].first,vec[i].second," \n"[i==len-1]);
	}
    return 0;
}