zoukankan      html  css  js  c++  java
  • 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("
    ");
        return 0;
    }
    

      

  • 相关阅读:
    机器学习问题之屌丝的女神专属
    【读点paper】irgan
    回老园子
    【Linux】常用命令收集
    【Matlab】基本语法
    【Ubuntu】log
    【Java 学习笔记】 Hadoop学习笔记
    【Algorithm】 字符串算法
    【WordPress】小卡的土豆园开张
    【Log】Self-Check Log
  • 原文地址:https://www.cnblogs.com/headboy2002/p/9439516.html
Copyright © 2011-2022 走看看