codeforces 822 C. Hacker, pack your bags!(思维+dp)
题目链接:http://codeforces.com/contest/822/submission/28248100
题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加一个标记就知道这是开始区间还是结束区间具体看一下代码。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define inf 1000000000000
using namespace std;
const int M = 2e5 + 10;
typedef long long ll;
struct TnT {
int sta , cau , flag;
ll val;
}a[M << 1];
bool cmp(TnT x , TnT y) {
if(x.sta == y.sta) return x.flag > y.flag;
return x.sta < y.sta;
}
ll dp[M];//dp[i]存储之前状态区间长度为i的最小花费
int main() {
int n;
ll x;
scanf("%d%lld" , &n , &x);
int cnt = 0;
for(int i = 0 ; i < n ; i++) {
int l , r;
ll c;
scanf("%d%d%lld" , &l , &r , &c);
a[cnt].sta = l , a[cnt].flag = 1 , a[cnt].cau = r - l + 1 , a[cnt].val = c;
a[++cnt].sta = r , a[cnt].flag = -1 , a[cnt].cau = r - l + 1 , a[cnt].val = c;
cnt++;
}
sort(a , a + cnt , cmp);
for(int i = 0 ; i < M ; i++) dp[i] = inf;
ll ans = inf;
for(int i = 0 ; i < cnt ; i++) {
if(a[i].flag == 1) {
ll sum = x - a[i].cau;
if(sum >= 0) {
if(dp[sum] < inf) ans = min(ans , a[i].val + dp[sum]);
}
}
else {
dp[a[i].cau] = min(dp[a[i].cau] , a[i].val);
}//这里的标记决定了dp是否要更新,显然在区间结束时就可以更新dp了
}
if(ans < inf) printf("%lld\n" , ans);
else printf("-1\n");
return 0;
}
codeforces 822 C. Hacker, pack your bags!(思维+dp)的更多相关文章
- CF822C Hacker, pack your bags!(思维)
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- CF-822C Hacker, pack your bags! 思维题
题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚 ...
- 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 ...
- 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 ...
- 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 Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
随机推荐
- 【iOS】The identity used sign the executable is no longer valid.
之前就遇到过这个问题,如图: 今天又遇到了,证书过期的问题. 需要访问苹果开发者的官网 http://developer.apple.com 来解决. 参考:How to fix “The ident ...
- Appium+python自动化(二十六)- 烟花一瞬,昙花一现 -Toats提示(超详解)
简介 今天宏哥在这里首先给小伙伴们和童鞋们分享一个有关昙花的小典故:话说昙花原是一位花神,她每天都开花,四季都灿烂.她还爱上了每天给她浇水除草的年轻人.后来,此事给玉帝得知.于是,玉帝大发雷霆,要拆散 ...
- ceph log机制
Log 是每个项目必须的,他是跟踪问题的最直接的依据.Ceph 也设计自己的log机制. 初始化启动log实例,启动log线程. _log = new ceph::log::Log(&_con ...
- C#实现简单爬虫
分享之前写过的一个爬虫,采集数据,存入数据库的简单实现. github地址:https://github.com/CodesCreator/biu-biu-biu-
- Spring文档学习
Spring文档学习 参考Spring Framework Documentation学习 1. IoC 容器 1.1 容器实例化 <beans> <import resource= ...
- 冬天苹果笔记macbookpro消除静电的方法
冬天mac除静电的方法 1.mac虽然声称不需要关机,但和apple技术人员沟通后,还是需要1周进行一次关机操作 2.知乎上的回答:https://www.zhihu.com/question/195 ...
- struts的上传下载
文件上传 添加jar包 commons-io-1.3.2.jar commons-fileupload-1.2.1.jar 前台页面 form表单 method值为post 添加"encty ...
- 洛谷 P4127 [AHOI2009]同类分布
题意简述 求l~r之间各位数字之和能整除原数的数的个数. 题解思路 数位DP 代码 #include <cstdio> #include <cstring> typedef l ...
- Mybatis案例超详解(上)
Mybatis案例超详解(上) 前言: 本来是想像之前一样继续跟新Mybatis,但由于种种原因,迟迟没有更新,快开学了,学了一个暑假,博客也更新了不少,我觉得我得缓缓,先整合一些案例练练,等我再成熟 ...
- 集合中Iterator迭代器的使用以及实现原理。
collection集合元素通用的获取方式,在取之前先要判断集合中有没有元素,如果有就把这个元素取出来,继续在判断,如果还有就再取出来,一直把集合中的元素全取出来,这种去出方式叫做迭代. 迭代器的作用 ...