HDU 6546

Function

Problem Description
wls 有 n 个二次函数 Fi(x) = aix2 + bix + ci (1 ≤ i ≤ n).
现在他想在∑ni=1xi = m 且 x 为正整数的条件下求∑ni=1Fi(xi)的最小值。
请求出这个最小值。

Input
第一行两个正整数 n, m。
下面 n 行,每行三个整数 a, b, c 分别代表二次函数的二次项, 一次项,常数项系数。
1 ≤ n ≤ m ≤ 100, 000
1 ≤ a ≤ 1, 000
−1, 000 ≤ b, c ≤ 1, 000

Output
一行一个整数表示答案。

Sample Input

2 3
1 1 1
2 2 2

Sample Output

13

HINT
由f(x+1)-f(x)得到a(2x+1)+b,这就是x增加后f的增长数量。
又因为a>0,所以全部从x=1开始,所以有m-n个数还未被使用,循环m-n次,把数据用上,求∑ni=1Fi(xi)的最小值,
Code:

#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
struct score
{
    int a,b,c;
    int x;
    int xxx;
    bool operator<(const score &q)const
    {
        return xxx>q.xxx;
    }
};
priority_queue<score,vector<score>,less<score> >x;
int main()
{
    int n,m;
    score temp;
    ll sum=0;
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {

        cin>>temp.a>>temp.b>>temp.c;
        temp.x=1;
        temp.xxx=temp.a*(2*temp.x+1)+temp.b;
        x.push(temp);
        sum+=temp.a+temp.b+temp.c;
    }
    for(int i=0; i<m-n; i++)
    {
        score t;
        t=x.top();
        x.pop();
        sum+=t.xxx;
        t.x++;
        t.xxx=t.a*(2*t.x+1)+t.b;
        x.push(t);
    }
    cout<<sum<<endl;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值