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. 超时空英雄传说2复仇魔神完全攻略&秘技

    ╓─╥───────────────────────────────────────────────────╥─╖ ║ ║ 超 時 空 英 雄 傳 說 2 ║ ║ ║ ║ --復 仇 魔 神-- ║ ...

  2. gsoap工具生成wsdl接口 注意事项

    wsdl是通过wsdl文件作为不同应用的通信接口,所以如何生成wsdl语言很重要,但是很多时候我们发现自己编写的头文件通过gsoap工具soapcpp2.exe从头文件中无法正常生成对应的wsdl语言 ...

  3. JavaWeb项目——博客系统

    系统介绍 博客是互联网平台上的个人信息交流中心.通常博客就是用来发表文章,所有的文章都是按照年份和日期排列,有些类似斑竹的日记.看上去平淡无奇,毫无可炫耀之处,但它可以让每个人零成本.零维护地创建自己 ...

  4. spring boot的gradle整合日志

    1.引入包configurations { providedRuntime // remove default logger all*.exclude group: 'org.springframew ...

  5. 2.GoF 的 23 种设计模式的分类和功能

    1. 根据目的来分 根据模式是用来完成什么工作来划分,这种方式可分为创建型模式.结构型模式和行为型模式 3 种. 创建型模式:用于描述“怎样创建对象”,它的主要特点是“将对象的创建与使用分离”.GoF ...

  6. 可迭代对象,迭代器对象,for循环

    迭代器:迭代的工具.迭代是更新换代,如你爷爷生了你爹,你爹生了你,迭代也可以说成是重复,并且但每一次的重复都是基于上一次的结果来的.如计算机中的迭代开发,就是基于软件的上一个版本更新.以下代码就不是迭 ...

  7. 201871010104-陈园园 《面向对象程序设计(java)》第十四周学习总结

    201871010104-陈园园 <面向对象程序设计(java)>第十四周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...

  8. uiautomator 调试例子

    package com.bing.cn; import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class Dem ...

  9. (day47)jQuery

    目录 一.初识jQuery (一)jQuery介绍 (二)版本介绍 (三)jQuery对象 (四)相关网站 (五)基础语法 二.查找标签 (一)基本选择器 (1)id选择器 (2)标签选择器 (3)c ...

  10. LeetCode237-Delete_Node_In_A_Linked_List

    delete-node-in-a-linked-list public void deleteNode(ListNode node) { node.val = node.next.val; node. ...