Function

\(\text{Alice}\) 有 \(n\) 个二次函数 \(F_i(x)=a_ix^2+b_ix+c_i(i \in [1,n])\)。

现在他想在 \(\sum_{i=1}^{n}{x_i=m}\) 且 \(x\) 为正整数的条件下求 \(\sum_{i=1}^n{F_i(x_i)}\) 的最小值。

请求出这个最小值。

Input

第一行两个正整数\(n,m。\)

下面\(n\)行,每行三个整数\(a,b,c,\)分别代表二次函数的二次项,一次项,常数项系数。

Output

一行一个整数表示答案。

Sample Input

2 3

1 1 1

2 2 2

Sample Output

13

Data range

对于全部测试数据满足:

  • \(a_i\in[1,10^3]\)
  • \(b_i,c_i\in[-10^3,10^3]\)
  • \(n\leq m\)
测试点编号 \(m\)
1 ~ 2 \(\leqslant 10\)
3 ~ 4 \(\leqslant 100\)
5 ~ 6 \(\leqslant 500\)
7 ~ 10 \(\leqslant 5 \times 10^3\)
11 ~ 20 \(\leqslant 10^5\)

思路:

先给每个函数的\(x\)赋为\(1\),再把\(f_i(x_i+1)-f_i(x_i)\)与\(i\)存入优先队列,按\(\Delta f_i\)进行\(x_i+1\)的操作\(,\)再把\(f_i(x_i+1)-f_i(x_i)\)与\(i\)塞回优先队列\(,\)重复\(m-n\)次

证明:

\(\because f^{'}_i(x)=2a_i+b_i\And a_i \geq 1\)

\(\therefore \Delta f_i\)随\(x_i+1\)操作单调增加

又\(\because\)要求\(\sum_{i=1}^nf_i(x_i)\)最小

\(\therefore\)最小的\(\Delta f_i\)一定要执行\(x_i+1\)操作

\(\mathfrak{Talk\ is\ cheap,show\ you\ the\ code.}\)

#include<cstdio>
#include<cmath>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
# define Type template<typename T>
# define read read1<ll>()
Type inline T read1()
{
T t=0;
char k;
bool fl=0;
do k=getchar(),(k=='-')&&(fl=1);while('0'>k||k>'9');
while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
return fl?-t:t;
}
# define A pair<ll,int>
# define ll long long
priority_queue<A,vector<A>,greater<A> >q;
int s,nx[100001],m;
ll a[100001],b[100001],c[100001],ans;
ll f(ll x,int n){return a[n]*x*x+b[n]*x+c[n];}
int main()
{
freopen("function.in","r",stdin);
freopen("function.out","w",stdout);
s=read;m=read-s;
for(int i=0;i++^s;nx[i]=1)
{
a[i]=read,b[i]=read,c[i]=read;
q.push(A(f(2,i)-f(1,i),i));
ans+=f(1,i);
}
while(m--)
{
A tem=q.top();
q.pop();
ans+=tem.first;
++nx[tem.second];
tem.first=f(nx[tem.second]+1,tem.second)-f(nx[tem.second],tem.second);
q.push(tem);
}
printf("%lld\n",ans);
return 0;
}

hdu6546 Function的更多相关文章

  1. 通过百度echarts实现数据图表展示功能

    现在我们在工作中,在开发中都会或多或少的用到图表统计数据显示给用户.通过图表可以很直观的,直接的将数据呈现出来.这里我就介绍说一下利用百度开源的echarts图表技术实现的具体功能. 1.对于不太理解 ...

  2. jsp中出现onclick函数提示Cannot return from outside a function or method

    在使用Myeclipse10部署完项目后,原先不出错的项目,会有红色的叉叉,JSP页面会提示onclick函数错误 Cannot return from outside a function or m ...

  3. JavaScript function函数种类

    本篇主要介绍普通函数.匿名函数.闭包函数 目录 1. 普通函数:介绍普通函数的特性:同名覆盖.arguments对象.默认返回值等. 2. 匿名函数:介绍匿名函数的特性:变量匿名函数.无名称匿名函数. ...

  4. 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()

    1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...

  5. jquery中的$(document).ready(function() {});

    当文档载入时执行function函数里的代码, 这部分代码主要声明,页面加载后 "监听事件" 的方法.例如: $(document).ready( $("a") ...

  6. Function.prototype.toString 的使用技巧

    Function.prototype.toString这个原型方法可以帮助你获得函数的源代码, 比如: function hello ( msg ){ console.log("hello& ...

  7. 转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38

    转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38http://space.itpub. ...

  8. [Xamarin] 透過Native Code呼叫 JavaScript function (转帖)

    今天我們來聊聊關於如何使用WebView 中的Javascript 來呼叫 Native Code 的部分 首先,你得先來看看這篇[Xamarin] 使用Webview 來做APP因為這篇文章至少講解 ...

  9. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

随机推荐

  1. Gitlab的CI/CD初尝试

    初衷:今天公司的前端和测试人员吵起来了.原因是测试埋怨前端人员把Bug的状态更改为已解决,结果代码根本没提交,而前端人员埋怨测试测的太频繁了,需要打几个环境的包不方便.又要改东西又要频繁打包费时间.凡 ...

  2. jdk8 HashMap tableSizeFor

    今天读jdk8  HashMap源码,构造函数中 根据initialCapacity初始化threshold public HashMap(int initialCapacity, float loa ...

  3. tkinter中的messagebox

    from tkinter import * from tkinter import messagebox def myMsg(): messagebox.showinfo("My Messa ...

  4. shell 统计nginx日志中从指定日期到结束日期之间每天指定条件匹配的总次数

    公司给出一个需求,指定时间内,统计请求driver.upload.position(司机位置上报接口)中,来源是华为push(come_from=huawei_push)的数量,要求是按天统计. 看一 ...

  5. AI2(App Inventor 2)离线版服务器(AI伴侣2.47版)

    提供这个版本的原因: 与app.gzjkw.net的源代码版本尽可能的接近,这样导入app.gzjkw.net源文件的时候不会有“该项目由新版App Inventor系统创建,我们仍然尝试将其加载,但 ...

  6. 【转载】CMake 两种变量原理

    原文地址:https://cslam.cn/archives/c9f565b5.html 摘要: 本文记录一下 CMake 变量的定义.原理及其使用.CMake 变量包含 Normal Variabl ...

  7. Python3字典排序

    创建一个字典 dict1={'a':2,'b':3,'c':8,'d':4} 1.分别取键.值 取字典的所有键,所有的值,利用dict1.keys(),dict1.vaules(), 由于键,值有很多 ...

  8. 基于Arduino和python的串口通信和上位机控制

    引言 经常的时候我们要实现两个代码之间的通信,比如说两个不同不同人写的代码要对接,例如将python指令控制Arduino控件的开关,此处使用串口通信是非常方便的,下面笔者将结合自己踩过的坑来讲述下自 ...

  9. 目标检测论文解读1——Rich feature hierarchies for accurate object detection and semantic segmentation

    背景 在2012 Imagenet LSVRC比赛中,Alexnet以15.3%的top-5 错误率轻松拔得头筹(第二名top-5错误率为26.2%).由此,ConvNet的潜力受到广泛认可,一炮而红 ...

  10. 习题6-2 使用函数求特殊a串数列和

    #include <stdio.h> int fn(int a, int n); int SumA(int a, int n); int main() { int a, n; scanf_ ...