P2085 最小函数值

题目链接hhh:https://www.luogu.org/problemnew/show/P2085
好嘛,运气真好,刚A掉序列合并,正好碰到这题,可以说是序列合并的升级版了 那么简单说一下思路,首先,最小值肯定出在当x=1的情况下的N个值中,那么将x=1的情况全部扔进小根堆里并用结构体确定最小值的下标,那么在调用此下标时,x就要加一,并出堆,实现代码如下:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cmath>
 4 #include<queue>
 5 #include<cstring>
 6 #include<iostream>
 7 using namespace std;
 8 
 9 struct node{
10     int k,l,ans;
11 };
12 int n,m,y;
13 int a[10005],b[10005],c[10005],z[10005];
14 priority_queue < node,vector<node>,greater<node> > zy;
15 
16 bool operator >(const node &a,const node &b){
17     return a.ans>b.ans;
18 }
19 
20 int main(){
21     scanf("%d%d",&n,&m);
22     for(int i=1;i<=n;i++){
23         scanf("%d%d%d",a+i,b+i,c+i);
24         z[i]=1;
25         zy.push((node){i,z[i],a[i]*z[i]*z[i]+b[i]*z[i]+c[i]});
26     }
27     while(m--){
28         printf("%d ",zy.top().ans);
29         int h=zy.top().k;
30         z[h]++;
31         zy.pop();
32         zy.push((node){h,z[h],a[h]*z[h]*z[h]+b[h]*z[h]+c[h]});
33     }
34     return 0;
35 }

好的就酱紫,还有不知道多少篇要写嘤嘤嘤

新人开博鼓励一下吧~~

posted @ 2019-07-02 21:22  喵呜,颜儿ღ  阅读(181)  评论(0编辑  收藏  举报