Luo Gu P2085 minimum value function template STL problem-solving report

See the original title ( https://www.luogu.org/problem/show?pid=2085 )
In fact, this question also had to fight violence easiest way function value can be calculated for each function all 100 deposit into an array th order output was then drained to be all -
in fact, the AC solution is to build a heap and then thrown to the calculated value m to the smallest number out of the line ~
paste Code:

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

int a[10010],b[10010],c[10010];
int f[10010][10010];
inline int read(){
    int num;
    char ch;
    while((ch=getchar())<'0' || ch>'9');
    num=ch-'0';
    while((ch=getchar())>='0' && ch<='9'){
        num=num*10+ch-'0';
    }
    return num;
}
inline void out(int x){
    if(x>=10){
         out(x/10);
    }
    putchar(x%10+'0');
}

priority_queue<int> q;

int main(){
    int n,m;
    n=read(),m=read();
    for(register int i=1;i<=n;i++){
        a[i]=read(),b[i]=read(),c[i]=read();
    }
    int i=0;
    for(register int j=1;j<=n;j++){
        i++;
        for(register int w=1;w<=100;w++){
            f[j][w]=a[i]*w*w+b[i]*w+c[i];
            q.push(-f[j][w]);//扔进去(-是为了把原来的顶最大变为顶最小) 
        }
    }
    for(register int j=1;j<=m;j++){
        int tmp;
        tmp=q.top();
        q.pop();
        out(-tmp);//恢复-号并输出 
        printf(" ");
    }
    return 0;
}
Published 41 original articles · won praise 58 · views 60000 +

Guess you like

Origin blog.csdn.net/a1351937368/article/details/78069224