博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nssl1269-射击【贪心,堆】
阅读量:2023 次
发布时间:2019-04-28

本文共 563 字,大约阅读时间需要 1 分钟。

正题


题目大意

有n个东西,东西必须在 a i   s a_i\ s ai s前破坏,破坏后可以获得 w i w_i wi价值,求最大价值。


解题思路

我们可以将时间从大到小排序,然后用堆,每次处理价值最大的就好了。


code

#include
#include
#include
#define ll long long#define N 200100using namespace std;struct node{
ll t,w;}a[N];ll n,last,ans;priority_queue
q;bool cmp(node x,node y)//排序{
return x.t==y.t?x.w>y.w:x.t>y.t;}int main(){
scanf("%lld",&n); for(ll i=1;i<=n;i++) scanf("%lld%lld",&a[i].t,&a[i].w); sort(a+1,a+1+n,cmp); for(ll i=1;i<=n;i++) {
if(a[i].w<0) continue; q.push(a[i].w); for(ll j=a[i+1].t;j

转载地址:http://mxzaf.baihongyu.com/

你可能感兴趣的文章
GitHub提交的时显示Updates were rejected because the remote contains work that you do
查看>>
mvc(1)——新建一个ASP.NET MVC项目
查看>>
mvc(2)——路由的理解(1)
查看>>
mvc(3)——渲染Web界面
查看>>
MVC(4)——学习mvc的基础_C#语言的语言特性
查看>>
SQL Server日志文件过大 大日志文件清理方法 不分离数据库
查看>>
如何执行超过500MB的SqlServer 脚本文件
查看>>
mvc(5)——URL路由_1_定义路由(映射url到动作方法)
查看>>
mvc(5)——URL路由_2_定义自定义片段变量
查看>>
mvc(5)——URL路由_3_约束路由
查看>>
mvc(5)——URL路由_4_属性路由
查看>>
mvc(5)——URL路由_5_高级特性
查看>>
mvc(6)——控制器和动作(不包含动作的输出)
查看>>
mvc(7)——过滤器
查看>>
mvc(8)——总结
查看>>
如何在sql server中使用循环语句
查看>>
JavaScript中DOM
查看>>
通过ADO.NET连接数据原理
查看>>
ADO.NET连接池
查看>>
类不需要实例化也能直接用
查看>>