zoukankan      html  css  js  c++  java
  • 洛谷P2085最小函数值题解

    题目

    首先我们先分析一下题目范围,(a,b,c) 都是整数,因此我们可以得出它的函数值在((0,+infty ))上是单调递增的,,然后我们可以根据函数的性质,将每个函数设置一个当前指向位置,都从从小的自变量开始找,每次找到最小的函数,并将最小函数的当前指向位置+1,因为并不知道最小函数自变量+1后的因变量是否要比现在的值要大,因此在下一次的比较中也要比较。且我们可以用堆来优化。

    代码

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    using namespace std;
    int a[10010], b[10010], c[10010], pos[10010];
    struct cym {
    	int id, y;
    }e[10010];
    bool operator < (cym a, cym b)
    {
    	return a.y > b.y;
    }
    priority_queue <cym> q;
    int main()
    {
    	int n, m;
    	scanf("%d%d", &n, &m);
    	for (int i = 1; i <= n; i++)
    	{
    		scanf("%d%d%d", &a[i], &b[i], &c[i]);
    			q.push({i, a[i] + b[i] + c[i]});
    		pos[i] = 1;
    	}
    	while (m--)
    	{
    		cym now = q.top(); q.pop();
    		printf("%d ", now.y);
    		q.push({now.id, ++pos[now.id] * pos[now.id] * a[now.id] + pos[now.id] * b[now.id] + c[now.id]});
    	}
    }
    
  • 相关阅读:
    with check option(视图 )
    @@ERROR
    事务处理
    含有自增序列的表中使用truncate与delete的不同结果
    Oracle中的通配符
    Java方法重载
    java递归方法
    Oracle中的for语句
    Uboot 2014.07 makefile分析
    linux内核目录结构
  • 原文地址:https://www.cnblogs.com/liuwenyao/p/10121372.html
Copyright © 2011-2022 走看看