【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 ...
随机推荐
- 前端的console.log的效果写法
不说废话,直接上代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- http_build_query 字符串拼接
http_build_query 字符串拼接 产生一个urlencode之后的请求字符串. 1.将数组转化成url问号(?)后的字符串 <?php $date=array( 'name'=> ...
- php查询字符串是否存在 strpos
/*** 查询字符是否存在于某字符串** @param $haystack 字符串* @param $needle 要查找的字符* @return bool*/function str_exists( ...
- Microsoft Visual Studio 2015打开TFS大量报错问题解决方案
用vs2015打开项目出现如图错误,尝试对XX项执行 添加 操作时遇到 XX 个错误,因为公司项目比较大,这个错误一直在弹,搜索了下,没有找到出现类似问题的解决方案. 因为这个路径是TFS(Team ...
- [CTSC2007][APIO2007]数据备份Backup
题目:BZOJ1150.codevs1615.洛谷P3620 题目大意:有n个点,k条链,每个点离原点有一定的距离.要你用k条链连接2k个点,使得k条链的长度最短. 解题思路:毕竟是CTSC级别的题目 ...
- session 超时跳转登陆页面
/** * session超时跳转登陆页面 * @author zhangdong * 2017年10月24日 */ @Aspect @Component public class SessionTi ...
- react-native 编译报错: undefined is not an object (evaluating '_react2.PropTypes.func')
情况通报: 因为是我的二维码模块报错,提示报错代码如下 重要信息是下面的红色字体部分(Android 模拟器红屏) undefined is not an object (evaluating '_r ...
- Nginx 安装 自用
hostnamectl set-hostname nginx systemctl stop firewalld.service systemctl disable firewalld.service ...
- 别了WindowsXP
生命中有太多的迎来送往,今日全世界都在告别它. 虽然自己已经在很久之前没有用XP系统了.告别它不如在一定意义上告别自己的一段时光... 2001年个人第一台电脑...初次安装XP,两张光盘一张安装盘一 ...
- python字典对象的update()方法
使用字典对象的update()方法,如A.update(B),将B字典的键值对一次性全部添加到A字典对象,当A字典为空时,相当于深复制,非常方便.如果两个字典中存在相同的键,则进行值的更新. A={} ...