CF822C Hacker, pack your bags!
思路:
对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可。于是可以开一个数组a[],a[i]表示所有能与i配对的区间(duration为x - i)的最小花费。计算的时候根据区间左端点由小到大依次更新就可以满足区间不重叠的限制,具体参见代码。
实现:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std; typedef long long ll;
const ll MAXN = , INF = 0x3f3f3f3f3f3f3f3f;
typedef pair<ll, ll> P;
vector<P> L[MAXN], R[MAXN];
ll a[MAXN]; int main()
{
ll n, x, l, r, c;
scanf("%I64d %I64d", &n, &x);
fill(a, a + MAXN, INF);
for (int i = ; i < n; i++)
{
scanf("%I64d %I64d %I64d", &l, &r, &c);
L[l].push_back({r - l + , c});
R[r].push_back({r - l + , c});
}
ll ans = INF;
for (int i = ; i < MAXN; i++)
{
for (auto it : L[i])
{
if (it.first >= x) continue;
ans = min(ans, a[x - it.first] + it.second);
}
for (auto it : R[i])
a[it.first] = min(a[it.first], it.second);
}
cout << (ans == INF ? - : ans) << endl;
return ;
}
CF822C Hacker, pack your bags!的更多相关文章
- CF822C Hacker, pack your bags!(思维)
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...
- CF-822C Hacker, pack your bags! 思维题
题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚 ...
- Codeforces822 C. Hacker, pack your bags!
C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心
C. Hacker, pack your bags! It's well known that the best way to distract from something is to do ...
- CodeForces 754D Fedor and coupons&&CodeForces 822C Hacker, pack your bags!
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codefroces 822C Hacker, pack your bags!
C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces 822C Hacker, pack your bags! - 贪心
It's well known that the best way to distract from something is to do one's favourite thing. Job is ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags!(更新数组)
传送门 题意 给出n个区间[l,r]及花费\(cost_i\),找两个区间满足 1.区间和为指定值x 2.花费最小 分析 先用vector记录(l,r,cost)和(r,l,cost),按l排序,再设 ...
随机推荐
- 洛谷 P1555 尴尬的数字
P1555 尴尬的数字 题目背景 Bessie刚刚学会了不同进制数之间的转换,但是她总是犯错误,因为她的两个前蹄不能轻松的握住钢笔. 题目描述 每当Bessie将一个数转换成新的进制时,她总会写错一位 ...
- Ubuntu 16.04 GNOME在桌面左侧添加启动器(Launcher)
安装Dash to Dock: git clone https://github.com/micheleg/dash-to-dock.git cd dash-to-dock/ make make in ...
- JSP中访问数据库
在JSP中访问数据库使用的是JSTL标签,本文不按照http://wiki.jikexueyuan.com/project/jsp/database-access.html此方法进行实践,而是采用之前 ...
- DTRACE简介(2)
By samwan on 三月 21, 2007 通过上一次的介绍,相信大家对DTRACE已经有了一个初步的认识.上一次结束时专门留了一个例子,可能大家第一次看有很多不明白的地方,没有关系,随着我们对 ...
- HDD
硬盘 SCSI ★ Host adapter ★ SCSI standard ★ Bus socket ★ Signal fashion ★ SCAM ★ Bus main control ★ Dri ...
- 017 SSH
Router>en Router#config t Enter configuration commands, one per line. End with CNTL/Z. Router(co ...
- php把时间计算成几分钟前,几小时前,几天前的函数
function time_tran($the_time){ $now_time = date("Y-m-d H:i:s",time()+8*60*60); $now_time = ...
- Lua学习笔记7:时间和日期
lua中的时间类似于C语言中的时间,例如以下: local time = os.time() print(time) local t = os.date("*t") for k,v ...
- [办公自动化]如何在windows7中编辑hosts文件 (提示权限不够)
请按如下步骤尝试: 1.在开始菜单里,单击“所有程序”,找到“附件”,单击找到里面的“记事本”,右键,然后选择“以管理员身份运行”,如果有对话框,选择“是”.2.然后单击记事本窗口的“文件”菜单,选择 ...
- 各种comprehension
1 什么是comprehension list.set.dict.generator等本质上是集合.所以,数学上的集合的表示引入到python中,{x| x属于某个集合}. 所以,comprehens ...