当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 洛谷 P2085 最小函数值

洛谷 P2085 最小函数值

2019年08月02日  | 移动技术网IT编程  | 我要评论

异世之屠龙传奇,漫画kuku,小阿姨香云

目录


题目

思路

首先这些函数全部单带递增,因为$a$,$b$,$c$都是正整数。
我们将全部的函数的$x$为$1$时的函数值放入优先度列(小根堆),然后输出并弹出堆顶元素,将该函数的$x++$再将函数值放入优先队列。

$code$

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#define maxn 10001
using namespace std;
int n,m;
int a[maxn],b[maxn],c[maxn];
struct info{
    int num,now,w;
    bool operator > (const info xx) const{
        return w>xx.w;
    }
}fff[maxn];
priority_queue<info,vector<info>,greater<info> > q;
inline int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f?-x:x;
}

int main(){
    n=read(),m=read();
    for(int i=1;i<=n;++i){
        a[i]=read(),b[i]=read(),c[i]=read();
    }
    for(int i=1;i<=n;++i){
        fff[i].now=1,fff[i].num=i;
        fff[i].w=a[i]+b[i]+c[i];
        q.push(fff[i]);
    }
    while(m--){
        info temp=q.top();
        printf("%d ",temp.w);
        q.pop();
        temp.now++;
        temp.w=(a[temp.num]*temp.now*temp.now)+(b[temp.num]*temp.now)+c[temp.num];
        q.push(temp);
    }
    puts("");
    return 0;
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网