luogu2085 最小函数值

题目大意

  有n个函数,分别为F1,F2,...,Fn。定义Fi(x)=Ai*x^2+Bi*x+Ci (x,Ai,Bi,Ci∈N*)。给定这些Ai、Bi和Ci,请求出所有函数的所有函数值中最小的m个。

题解

  审题!$A_i, B_i>0$!这说明对称轴在y轴左侧!所以正半轴上x值是单调递增的!这样我们就可以想到用单调队列来解决这个问题了。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int MAX_N = 10010;

struct Func
{
    int a, b, c;
    int x, y;
    
    void GetY()
    {
        y = a * x * x + b * x + c;
    }
    
    bool operator < (const Func &a) const
    {
        return y > a.y;
    }
}_fs[MAX_N];

int main()
{
    int totFunc, outCnt;
    scanf("%d%d", &totFunc, &outCnt);
    for (int i = 1; i <= totFunc; i++)
    {
        scanf("%d%d%d", &_fs[i].a, &_fs[i].b, &_fs[i].c);
        _fs[i].x = 1;
        _fs[i].GetY();
    }
    static priority_queue<Func> q;
    for (int i = 1; i <= totFunc; i++)
        q.push(_fs[i]);
    while (outCnt--)
    {
        Func cur = q.top();
        q.pop();
        printf("%d ", cur.y);
        cur.x++;
        cur.GetY();
        q.push(cur);
    }
    printf("\n");
    return 0;
}

  

转载于:https://www.cnblogs.com/headboy2002/p/9439516.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值