博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
luogu2085 最小函数值
阅读量:4627 次
发布时间:2019-06-09

本文共 1114 字,大约阅读时间需要 3 分钟。

题目大意

  有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 
#include
#include
#include
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
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

你可能感兴趣的文章
5.Spring+Struts+Hibernate配置文件整合
查看>>
Unable to create request (bad url?) 解决方案
查看>>
网络对抗技术_实验三_密码破解技术
查看>>
vue-状态管理
查看>>
css实现等高布局
查看>>
CH03_06.mxml 一个文本输入框复制到另外一个文本输入框
查看>>
malloc/free和new/delete
查看>>
spoj104 highways 生成树计数(矩阵树定理)
查看>>
nginx配置多个域名
查看>>
ARM寻址方式
查看>>
pandas之时间序列
查看>>
补肾的十大食物是什么?
查看>>
iPhone开发之 - 苹果推送通知服务(APNs)编程
查看>>
ASP常用读取数据2个调用方式
查看>>
【大话UWB定位】之蓝牙定位的烦恼
查看>>
算法3-高级排序
查看>>
每天一个linux命令(17):whereis 命令
查看>>
Angular4+路由
查看>>
Codeforces-234C Weather
查看>>
面向对象编程思想及其相关内容
查看>>