PAT(甲级) 1009 Product of Polynomials (简易模拟)

#include
#include
#include
#include
#include
using namespace std;
const int maxn = 1000 + 5;
typedef struct {
	int exp;
	float coef;
}node;
int main(void)
{
	//freopen("in.txt", "r", stdin);
	int k;
	vector <node> p(10);
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> p[i].exp >> p[i].coef;
	}
	int n;
	cin >> n;
	vector <float> ans(maxn << 1);
	for (int i = 0; i < n; i++)
	{
		int e;
		float c;
		cin >> e >> c;
		for (int i = 0; i < k; i++)
		{
			ans[e + p[i].exp] += c * p[i].coef;
		}
	}
	int tot = 0;
	for (int i = (maxn << 1) - 1; ~i; i--)
		if (fabs(ans[i]) > 1e-2) tot++;
	cout << tot;
	for (int i = (maxn << 1) - 1; ~i; i--)
	{
		if (fabs(ans[i] - 0.0) > 1e-2) cout << " " << i << " " << setiosflags(ios::fixed) << setprecision(1) << ans[i];
	}
	return 0;
}

你可能感兴趣的:(模拟,PAT(甲级))