高精度解法:
#include <bits/stdc++.h>
using namespace std;
struct Func//表示一个函数
{
int a, b, c, x;
Func(int _a, int _b, int _c):a(_a), b(_b), c(_c)
{
x = 1;
}
Func(){}
int getVal()//求函数值
{
return a*x*x+b*x+c;
}
};
struct Cmp
{
bool operator () (Func &a, Func &b)
{
return b.getVal() < a.getVal();//优先条件为:函数值更小的Func对象更优先
}
};
int main()
{
priority_queue<Func, vector<Func>, Cmp> pq;
int n, m, a, b, c;
cin >> n >> m;
for(int i = 1; i <= n; ++i)
{
cin >> a >> b >> c;
pq.push(Func(a, b, c));
}
for(int i = 1; i <= m; ++i)
{
Func f = pq.top();//f表示一个函数
pq.pop();
cout << f.getVal() << ' ';
f.x++;//f的x值增加1
pq.push(f);
}
return 0;
}