【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)
接上一篇文章;
这里直接把左端点和右端点映射到vector数组上;
映射一个open和close数组;
枚举1..2e5
如果open[i]内有安排;
则用那个安排和dp数组来更新答案;
更新答案完之后,如果有close数组
则把close数组里面的安排用来更新dp数组;
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5;
const int INF = 2e9+10;
struct abc{
int l,r,cost;
};
int n,x,dp[N],ans = INF;
vector <abc> open[N+100],close[N+100];
int main(){
//Open();
Close();
cin >> n >> x;
abc temp;
rep1(i,1,n){
cin >> temp.l >> temp.r >> temp.cost;
open[temp.l].pb(temp);
close[temp.r].pb(temp);
}
int len;
rep1(i,1,N){
while (!open[i].empty()){
temp = open[i].back();
open[i].pop_back();
len = temp.r-temp.l+1;
if (x>=len){
if (dp[x-len] > 0)
ans = min(ans,dp[x-len]+temp.cost);
}
}
while (!close[i].empty()){
temp = close[i].back();
close[i].pop_back();
len = temp.r-temp.l+1;
if (dp[len]==0)
dp[len] = temp.cost;
else
dp[len] = min(dp[len],temp.cost);
}
}
if (ans==INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)的更多相关文章
- 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 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排序,再设 ...
- Codeforces Round #422 (Div. 2)
Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored ...
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP
E. Liar The first semester ended. You know, after the end of the first semester the holidays beg ...
- Codeforces Round #422 (Div. 2) B. Crossword solving 枚举
B. Crossword solving Erelong Leha was bored by calculating of the greatest common divisor of two ...
- Codeforces Round #422 (Div. 2) A. I'm bored with life 暴力
A. I'm bored with life Holidays have finished. Thanks to the help of the hacker Leha, Noora mana ...
- 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora
[题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...
- 【Codeforces Round #422 (Div. 2) B】Crossword solving
[题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...
随机推荐
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- NEC芯片特别说明
NEC芯片注意点: 1.堆栈和RAM共用,而且是程序中自定义堆栈的空间,堆栈是向下递减堆栈. 2.中断中标志位的清除可以不用手动清除,在中断服务程序中运行任何一条指令后自动清除. 3.中断服务程序有且 ...
- 捕捉soap的xml形式
下面是我以前对Php的soap接口进行抓包分析出的结果,这个分析在当服务端或者客户端的Php没有安装soap模块时,可以使用构建xml的方式实现相同的功能 服务端: $data = $HTTP_RAW ...
- vue生命周期-学习心得
每个Vue实例在被创建之前都要经过一系列的初始化过程,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.销毁等一系列过程,这个过程就是vue的生命周期. 1 vue生命周期图 {: ...
- /lib64和/usr/lib64和/usr/local/lib64的区别
简单说,/lib64是内核级的,/usr/lib64是系统级的,/usr/local/lib64是用户级的. /lib/ — 包含许多被 /bin/ 和 /sbin/ 中的程序使用的库文件.目录 /u ...
- UT源码+105032014018
设计佣金问题的程序 commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone).手机壳(Mobile phone shell).手机贴膜(Cellphon ...
- 魔兽争霸RPG游戏-军团战争-游戏经验总结
终于要写这篇了,上一篇是个意外. 2015年关注,一代鬼王Xun和GGL比赛.晚上11点之后,经常有水友赛.主播xun,会带着一帮小弟,玩一些游戏.比如魔兽争霸6v6,2v2,RPG游戏-军团战争,疯 ...
- Mybaties下的分页功能的实现
jsp页面 <!-- 页码 --> <div class="ipRListNav2"> <a href="zyxx.do?findZyxx& ...
- nodejs 实现简单 http 代理并缓存
var http = require('http'), fs = require("fs"), url = require('url'), querystring = requir ...
- bzoj1800: [Ahoi2009]fly 飞行棋(乱搞)
1800: [Ahoi2009]fly 飞行棋 题目:传送门 题解: 大水题,早上签个到 没什么好说的...搞个前缀和,算个周长... 周长为奇数肯定误解啊废话QWQ 那么看到n<=20,还不暴 ...