P2085 最小函数值

链接:Miku


显然在x>0的时候,函数都是随x增大而增大的

所以说嘛,优先队列就能搞出来


#include<iostream>
#include<cstdio> 
#include<algorithm>
#include<queue>
using namespace std;
int n,m;
int a[10001],b[10001],c[10001];
struct need{
    int x;
    int i;
    int v;
    friend bool operator < (need a,need b){
        return a.v>b.v;
    }
} now,x;
priority_queue <need>q ;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        now.x=1;
        now.i=i;
        now.v=a[i]+b[i]+c[i];
        q.push(now);
    }
    for(int i=1;i<=m;++i){
        x=q.top();
        q.pop();
        cout<<x.v<<" ";
        now.i=x.i;
        now.x=x.x+1;
        now.v=a[now.i]*now.x*now.x+now.x*b[now.i]+c[now.i];
        q.push(now);
    }
    return 0;
}

Ac

 

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇