题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少。

解题思路:看了大佬的才会写!其实和之前Codeforces 776C的写法有点像,遍历l,设以l为起始时间时长为time,看是否存在时长为x-time且与当前时段不相交的时间段,取最小值。

代码:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2e5+;
typedef pair<int,int>pii; vector<pii>v[N];//存放拿来拼凑的区段
vector<pii>rc[N];//用来存放接下来要遍历的区段
int mp[N]; int main(){
ios::sync_with_stdio(false);
int n,x;
cin>>n>>x;
for(int i=;i<=n;i++){
int l,r,cost;
cin>>l>>r>>cost;
//以l为索引存放区段
rc[l].push_back(pii(r,cost));
}
int ans=2e9+;
//遍历l的值
for(int l=;l<=2e5;l++){
for(int i=;i<rc[l].size();i++){
int r=rc[l][i].first;
int cost=rc[l][i].second;
int time=r-l+;
if(time>x)
continue;
//看是否存在与这段时间相加和为x,且不想交的时段
if(mp[x-time]){
ans=min(ans,mp[x-time]+cost);
}
//遍历过的放到左边区域
v[r].push_back(pii(time,cost));
}
//找v[l],也就是左边区域的v[r],因为下一次l2=l+1,肯定大于r,所以区间不会相交,可以直接拿来用
for(int i=;i<v[l].size();i++){
int time=v[l][i].first;
int cost=v[l][i].second;
if(!mp[time]||mp[time]>cost)
mp[time]=cost;
}
}
if(ans==2e9+)
cout<<-<<endl;
else
cout<<ans<<endl;
}

Codeforces 822C Hacker, pack your bags!(思维)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. CodeForces 822C Hacker, pack your bags!

    题意 给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为x且代价最低 思路 相同持续时间的放在一个vector中,内部再对起始时间排序,从后向前扫获取对应起始时间的最优代价,存在minn中 ...

  4. CF822C Hacker, pack your bags!(思维)

    Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...

  5. 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 ...

  6. CF-822C Hacker, pack your bags! 思维题

    题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚 ...

  7. 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 ...

  8. 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 ...

  9. codeforces 822 C. Hacker, pack your bags!(思维+dp)

    题目链接:http://codeforces.com/contest/822/submission/28248100 题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加 ...

随机推荐

  1. PHP关于VC9和VC6以及Thread Safe和Non Thread Safe版本选择的问题

    一.如何选择PHP5.3的VC9版本和VC6版本 VC6版本是使用Visual Studio 6编译器编译的,如果你的PHP是用Apache来架设的,那你就选择VC6版本.      VC9版本是使用 ...

  2. [知识点]C++中STL容器之map

    UPDATE(20190416):写完vector和set之后,发现不少内容全部引导到map上了……于是进行了一定的描述补充与更正. 零.STL目录 1.容器之map 2.容器之vector 3.容器 ...

  3. 手脱nSPack 2.2

    1.PEID查壳 深度扫描下:nSPack 2.2 -> North Star/Liu Xing Ping 2.载入OD,上来就是一个大跳转,F8单步跟下去 0040101B >- E9 ...

  4. jeecms上传文件限制导致413-Request Entity Too Large

    1:spring mvc 上传限制大小  配置是否允许在上传文件的大小 <bean id="multipartResolver" class="org.spring ...

  5. 报Cannot find /usr/local/tomcat/bin/setclasspath.sh错误

    错误如下: [root@RSP-DEVWEB03 bin]#sh startup.sh Cannot find /usr/local/tomcat8081/bin/setclasspath.sh Th ...

  6. SQL Server 2008过期导致MSSQLSERVER服务无法启动现象

    SQL Server 2008过期导致MSSQLSERVER服务无法启动现象:安装的是SQL Server 2008评估版,180天的试用期后,MSSQLSERVER服务就无法启动,手动启动就报告17 ...

  7. poj 1067 取石子游戏 (威佐夫博弈)

    取石子游戏 http://poj.org/problem?id=1067 Time Limit: 1000MS   Memory Limit: 10000K       Description 有两堆 ...

  8. Oracle数据库语句

    Oracle数据库语句 ORACLE支持五种类型的完整性约束 NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值. CHEC ...

  9. 持续集成工具Jenkins安装、部署、使用

    本文介绍jenkins,利用其做项目发布与持续集成交付工具. 一.Jenkins是什么? Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布 ...

  10. C++面试中可能考察的基础知识(1)

    1 C++中允许函数的嵌套调用,但不允许函数的嵌套定义 2 构建派生类对象时,先调用基类的构造函数,在调用成员对象的构造函数,最后调用派生类构造函数. 3 volatile关键字 volatile提醒 ...