【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 ...
随机推荐
- asp.net HTTP请求过程
http://blog.csdn.net/zxxSsdsd/article/details/51909860
- angular踩坑记录
ng-repeat和ng-click同时使用的时候,注意不能直接在ng-click当中写代码,必须在当前$scope中绑定一个事件,转为调用该事件.否则会出现意想不到的情况.具体原因点击这里. 使用自 ...
- 解决Windows下git需要每次都要ssh-add的问题
顽皮的很: 不知道怎么回事,每次打开git提交代码都需要ssh-add一下秘钥才可以正常提交: 不然就报错权限之类的问题: 怎么才能更方便一些? 卸了重装!我没试... 再或者是在 git 的安装目录 ...
- 多任务-进程之PID
1.进程pid,如何在程序中获取我们的进程号,从而查看当前的进程 # -*- coding:utf-8 -*- from multiprocessing import Process import o ...
- GDOI2017 再次酱油记
Day 0 13:00 pm 啊...今天中午一点钟从ez出发,感觉吼有趣啊.出发前先大喊一声****,在书包里放一本党史,感觉玄学可以救命[滑稽] 15:00 pm 到达东莞,坐标:石龙名冠金凯悦大 ...
- PHP中使用DOM读取解析XML属性值一例
先看XML文件结构,与常见的文件略有不同,数据并不是用闭合标签保存的,而是直接保存在属性值中. <?xml version="1.0" encoding="utf- ...
- redhat7.5 升级OpenSSH_7.8p1
1:拷贝编译好rpm安装包 [root@liwm ~]# scp -r root@192.168.31.130:/home/openssh7.8 /home/ root@192.168.31.130' ...
- 紫书 例题 11-2 UVa 1395(最大边减最小边最小的生成树)
思路:枚举所有可能的情况. 枚举最小边, 然后不断加边, 直到联通后, 这个时候有一个生成树.这个时候,在目前这个最小边的情况可以不往后枚举了, 可以直接更新答案后break. 因为题目求最大边减最小 ...
- CentOS上手动配置nginx.services
[Unit] Description=Dynamic web platform based on NGINX and LuaJIT After=network.target remote-fs.tar ...
- 9种常见的Android开发错误及解决方案
整理总结了9个Android开发中的错误以及解决方案,共同探讨进步! 1. 如果你的项目的R文件不见的话,可以试下改版本号在保存,R文件不见一般都是布局文本出错导致. 2. 布局文件不可以有大写字母 ...