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排序,再设 ...
随机推荐
- Java 输入一个正整数,按蛇形打印。
参考博客: http://yangyingming.com/article/371/ //输入一个正整数n(n<=30),输出n所对应的蛇形矩阵.举两个例子: //n=10时,蛇形矩阵为: ...
- CCNA参考链接
http://www.cisco.com/c/en/us/support/docs/lan-switching/vtp/10558-21.html http://www.cisco.com/c/en/ ...
- Mesos, Marathon, Docker 平台部署记录
Mesos, Marathon, Docker 平台部署记录 所有组件部署基于Ubuntu 14.04 x64 主机 IP 角色 master 192.168.1.3 Mesos Master, Ma ...
- Nginx中配置vue,react项目地址
如题 像以前在Nginx中配置域名解析的时候只需要在conf.d文件夹下添加对应的xx.conf文件(当然了你也可以在nginx.conf)下配置. 如果是以前的老项目只需要在配置文件中server内 ...
- 图像处理之基础---彩色转灰度算法优化rgb to yuv
File: StudyRGB2Gray.txtName: 彩色转灰度算法彻底学习Author: zyl910Version: V1.0Updata: 2006-5- ...
- 【codevs2011】【LNOI2013】最小距离之和
floyed水题 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstr ...
- unigui组件中client javascript delphi组件之间的操作
UniLabel组件: function OnClick(sender, e){ MainForm.UniLabel1.setText('Click!');} function Onmousemove ...
- override (C# Reference)
https://msdn.microsoft.com/en-us/library/ebca9ah3.aspx The override modifier is required to extend o ...
- 【CSU 1803】2016
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1803 Solution: 考虑两个数x,y乘积%2016=0 x×y≡0(MOD 2016) x= ...
- 【ZJOI2009】【Codevs 2347】假期的宿舍
http://codevs.cn/problem/2347/ Solution 二分图板子 连边:i认识j并且j是在校有床 i→j+n i有床i→i+n 还有就是找要在学校的人,1.有床不回2.没床的 ...