822C Hacker, pack your bags!
对我来说非常有启发的一条题目
机票具有往返两个时间点,做不交叉匹配的时候可以把一张机票一分为二,
每张机票按照时间点构造成两个事件,
对总的事件做排序就可以很轻松的做到无交叉匹配
bestCost[i]意思是时长i天的机票最少的花费,由于枚举时间点的缘故必定可行
代码:
#include<bits/stdc++.h>using namespace std;
#define ll long longconst int maxn=2e5+9;
const int inf=2e9+2;
int n,x,l,r,c;
int bestCost[maxn];struct CARD{int timePoint,len,cost,type;int operator<(const CARD &x){if(timePoint==x.timePoint)return type<x.type;return timePoint<x.timePoint;}
}arr[maxn<<1];int main(){scanf("%d%d",&n,&x);int cnt=0;for(int i=1;i<=n;i++){scanf("%d%d%d",&l,&r,&c);arr[++cnt]=CARD{l,r-l+1,c,-1};arr[++cnt]=CARD{r,r-l+1,c,1};} ll ans=inf;sort(arr+1,arr+1+cnt);fill(bestCost+1,bestCost+x+1,inf);for(int i=1;i<=cnt;i++){ //枚举时间点if(arr[i].type==-1){ //出发if(arr[i].len<x){ans=min(ans,1ll*arr[i].cost+bestCost[x-arr[i].len]);}}else{bestCost[arr[i].len]=min(bestCost[arr[i].len],arr[i].cost);}}if(ans>=inf)ans=-1;printf("%lld\n",ans);
}
自己的暴力在大数据上有的卡有的过,奥妙重重
转载于:https://www.cnblogs.com/Drenight/p/8611315.html
822C Hacker, pack your bags!相关推荐
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- codeforces round 422 div2 补题 CF 822 A-F
A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...
- 23岁一无所有怎么办_我搬到国外去创业,然后一无所有。
23岁一无所有怎么办 以我的名字还不到一美元,它仍然感觉不像是最低点. (With not even a dollar to my name, it still didn't feel like ro ...
- 英语影视台词---六、Saving Private Ryan Quotes
英语影视台词---六.Saving Private Ryan Quotes 一.总结 一句话总结: Saving Private Ryan is a 1998 American epic war fi ...
- kali kda安装 linux_全昭妍미연Bea MillerWolftylaKDA-THE BADDEST
全昭妍&미연&Bea Miller&Wolftyla&KDA-THE BADDEST FLAC 11/10 THE BADDEST - K/DA/전소연/미연/Bea ...
- 算法训练营 重编码_我在编码训练营中的经验(以及是否适合您)
算法训练营 重编码 by Florian Mueller 通过弗洛里安·穆勒(Florian Mueller) 我在编码训练营中的经验(以及是否适合您) (My experience with a c ...
- 与音乐,,纪念Arthur Rimbaud诞辰150周年
姓名:Arthur Rimbaud 生辰:1854年10月20日 祭日:1891年11月10日 地区:阿登纳省 国家:法兰西 职业:诗人 ,如果诗人是一种"职业"~ 写作 ...
- Ninth season nineteenth episode,Rachel had a dream. She kissed Joey??????
[Scene: Rachel and Joey's apartment] Joey: (talking to a pineapple in his hand) God, you're beautifu ...
- 给 perl hacker 们看的(ReShip)
究竟有多少种打印出 just another perl hacker 的方法呢? 看看就知道了 :-) %% #JoeCamel on http://www.perlmonks.com/ #note: ...
最新文章
- HMM(隐马尔科夫)用于中文分词
- linux ftp命令大全,linuxftp常用命令【图解】
- java rmi 入门实例
- 网络流入门题目 - bzoj 1001
- 115. cURL 简介(1)
- jvm内存分析和cpu耗时分析
- win7控件无法安装怎么办【系统天地】
- BurpSuite CA证书安装(拦截HTTPS协议)
- Navicat 局域网连接数据库
- 拼多多引流大法,日引百人太简单
- 保险巨头安盛将推出代币众筹保险服务
- STL库:vector
- smartfroms word编辑_word如何改变smartart word如何编辑smartart
- JS for循环实现 My cats are called Bill, Jeff, Pete, Biggles, and Jasmin.
- oracle oem 13c新特性,Oracle Database 12c - 新特性实现的历程与13c的预测
- spring-银行转账系统
- 分享快看点助手APK和源代码
- python初学者——1、变量
- 解决PyCharm和Spyder不能兼容pip下载第三方包的问题
- 电脑不识别U盘,U盘不显示怎么办?
热门文章
- 【前端 · 面试 】HTTP 总结(六)—— HTTP 版本区别
- 最全面、最详细的“前端模块化”总结
- 解决CentOS 6 字体变成方框的方法
- createwindow 和 dialogbox的区别
- 2021-02-28 配置Jetty+GeoServer-2.18.2允许CORS跨域访问 - 草稿
- PhoneGap的Android端插件开发
- python画卡通皮卡丘_实现童年Pokémon,教你用Python画一只属于自己的皮卡丘
- qt_3_Qt开发环境
- Ubuntu sublime text 3无法输入中文的解决办法
- 关于Android Studio Arctic Fox版本找不到Database Inspection这件事