接上一篇文章;

这里直接把左端点和右端点映射到vector数组上;

映射一个open和close数组;

枚举1..2e5

如果open[i]内有安排;

则用那个安排和dp数组来更新答案;

更新答案完之后,如果有close数组

则把close数组里面的安排用来更新dp数组;

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define Open() freopen("F:\\rush.txt","r",stdin)
  14. #define Close() ios::sync_with_stdio(0)
  15. typedef pair<int,int> pii;
  16. typedef pair<LL,LL> pll;
  17. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  18. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  19. const double pi = acos(-1.0);
  20. const int N = 2e5;
  21. const int INF = 2e9+10;
  22. struct abc{
  23. int l,r,cost;
  24. };
  25. int n,x,dp[N],ans = INF;
  26. vector <abc> open[N+100],close[N+100];
  27. int main(){
  28. //Open();
  29. Close();
  30. cin >> n >> x;
  31. abc temp;
  32. rep1(i,1,n){
  33. cin >> temp.l >> temp.r >> temp.cost;
  34. open[temp.l].pb(temp);
  35. close[temp.r].pb(temp);
  36. }
  37. int len;
  38. rep1(i,1,N){
  39. while (!open[i].empty()){
  40. temp = open[i].back();
  41. open[i].pop_back();
  42. len = temp.r-temp.l+1;
  43. if (x>=len){
  44. if (dp[x-len] > 0)
  45. ans = min(ans,dp[x-len]+temp.cost);
  46. }
  47. }
  48. while (!close[i].empty()){
  49. temp = close[i].back();
  50. close[i].pop_back();
  51. len = temp.r-temp.l+1;
  52. if (dp[len]==0)
  53. dp[len] = temp.cost;
  54. else
  55. dp[len] = min(dp[len],temp.cost);
  56. }
  57. }
  58. if (ans==INF)
  59. cout << -1 << endl;
  60. else
  61. cout << ans << endl;
  62. return 0;
  63. }

【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)的更多相关文章

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

  2. 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排序,再设 ...

  3. Codeforces Round #422 (Div. 2)

    Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored ...

  4. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)

    [题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...

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

  6. Codeforces Round #422 (Div. 2) B. Crossword solving 枚举

    B. Crossword solving     Erelong Leha was bored by calculating of the greatest common divisor of two ...

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

  8. 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora

    [题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...

  9. 【Codeforces Round #422 (Div. 2) B】Crossword solving

    [题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...

随机推荐

  1. LeetCode 190. Reverse Bits (算32次即可)

    题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...

  2. NEC芯片特别说明

    NEC芯片注意点: 1.堆栈和RAM共用,而且是程序中自定义堆栈的空间,堆栈是向下递减堆栈. 2.中断中标志位的清除可以不用手动清除,在中断服务程序中运行任何一条指令后自动清除. 3.中断服务程序有且 ...

  3. 捕捉soap的xml形式

    下面是我以前对Php的soap接口进行抓包分析出的结果,这个分析在当服务端或者客户端的Php没有安装soap模块时,可以使用构建xml的方式实现相同的功能 服务端: $data = $HTTP_RAW ...

  4. vue生命周期-学习心得

    每个Vue实例在被创建之前都要经过一系列的初始化过程,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.销毁等一系列过程,这个过程就是vue的生命周期. 1 vue生命周期图 {: ...

  5. /lib64和/usr/lib64和/usr/local/lib64的区别

    简单说,/lib64是内核级的,/usr/lib64是系统级的,/usr/local/lib64是用户级的. /lib/ — 包含许多被 /bin/ 和 /sbin/ 中的程序使用的库文件.目录 /u ...

  6. UT源码+105032014018

    设计佣金问题的程序 commission方法是用来计算销售佣金的需求,手机配件的销售商,手机配件有耳机(headphone).手机壳(Mobile phone shell).手机贴膜(Cellphon ...

  7. 魔兽争霸RPG游戏-军团战争-游戏经验总结

    终于要写这篇了,上一篇是个意外. 2015年关注,一代鬼王Xun和GGL比赛.晚上11点之后,经常有水友赛.主播xun,会带着一帮小弟,玩一些游戏.比如魔兽争霸6v6,2v2,RPG游戏-军团战争,疯 ...

  8. Mybaties下的分页功能的实现

    jsp页面 <!-- 页码 --> <div class="ipRListNav2"> <a href="zyxx.do?findZyxx& ...

  9. nodejs 实现简单 http 代理并缓存

    var http = require('http'), fs = require("fs"), url = require('url'), querystring = requir ...

  10. bzoj1800: [Ahoi2009]fly 飞行棋(乱搞)

    1800: [Ahoi2009]fly 飞行棋 题目:传送门 题解: 大水题,早上签个到 没什么好说的...搞个前缀和,算个周长... 周长为奇数肯定误解啊废话QWQ 那么看到n<=20,还不暴 ...