题意

给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为x且代价最低

思路

相同持续时间的放在一个vector中,内部再对起始时间排序,从后向前扫获取对应起始时间的最优代价,存在minn中,对时间 i 从前向后扫,在对应的k-i中二分找第一个不重合的区间,其对应的minn加上 i 的cost即为出发时间为 i 时的最优解

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n, k;
  4. struct EVE{
  5. int st,ed,val;
  6. EVE(){
  7. }
  8. EVE(int a,int b, int c){
  9. st = a, ed = b, val = c;
  10. }
  11. };
  12. int f,t,c;
  13. vector<EVE> v[];
  14. vector<int> minn[];
  15. int tmp[];
  16. bool cmp(EVE a, EVE b){
  17. return a.st<b.st;
  18. }
  19. int main(){
  20. scanf("%d%d",&n,&k);
  21. for(int i = ;i<n;i++){
  22. scanf("%d%d%d",&f,&t,&c);
  23. if(t-f+ >= k) continue;
  24. v[t-f+].push_back({f,t,c});
  25. }
  26. for(int i = ;i<=k;i++) sort(v[i].begin(),v[i].end(),cmp);
  27. for(int i = ;i<=k;i++){
  28. for(int j = v[i].size()-;j>=;j--){
  29. if(j==v[i].size()-) tmp[j]=v[i][j].val;
  30. else tmp[j]=min(v[i][j].val,tmp[j+]);
  31. }
  32. for(int j = ;j<v[i].size();j++){
  33. minn[i].push_back(tmp[j]);
  34. }
  35. }
  36. long long ans = 1e12;
  37. for(int i = ;i<=k;i++){
  38. if(v[k-i].empty()) continue;
  39. for(int j = ;j<v[i].size();j++){
  40. int ed = v[i][j].ed;
  41. long long cost = v[i][j].val;
  42. int le = , ri = v[k-i].size()-;
  43. if(v[k-i][ri].st<=ed) continue;
  44. int mid = le+ri>>;
  45. while(le<ri){
  46. mid = le+ri>>;
  47. if(v[k-i][mid].st<=ed) le = mid+;
  48. else ri = mid;
  49. }
  50. ans = min(ans, cost+minn[k-i][le]);
  51. }
  52. }
  53. if(ans == 1e12) printf("-1");
  54. else printf("%I64d",ans);
  55. return ;
  56. }

CodeForces 822C Hacker, pack your bags!的更多相关文章

  1. CodeForces 754D Fedor and coupons&&CodeForces 822C Hacker, pack your bags!

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. Codeforces 822C Hacker, pack your bags! - 贪心

    It's well known that the best way to distract from something is to do one's favourite thing. Job is ...

  3. Codeforces 822C Hacker, pack your bags!(思维)

    题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...

  4. Codefroces 822C Hacker, pack your bags!

    C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input s ...

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

  6. CF822C Hacker, pack your bags!(思维)

    Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...

  7. Codeforces822 C. Hacker, pack your bags!

    C. Hacker, pack your bags! time limit per test 2 seconds memory limit per test 256 megabytes input s ...

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

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

  9. codeforces 822 C. Hacker, pack your bags!(思维+dp)

    题目链接:http://codeforces.com/contest/822/submission/28248100 题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加 ...

随机推荐

  1. laravel门面DB返回数组配置

    在数据库配置文件中添加 'fetch' => PDO::FETCH_ASSOC, //但是这个配置好像是全局的,不能针对单个数据库连接进行配置 也可以在方法内使用php内置函数get_objec ...

  2. 【Leetcode_easy】784. Letter Case Permutation

    problem 784. Letter Case Permutation 参考 1. Leetcode_easy_784. Letter Case Permutation; 2. Grandyang; ...

  3. Spring Aop(十五)——Aop原理之Advised接口

    转发地址:https://www.iteye.com/blog/elim-2398726 Spring Aop原理之Advised接口 通过之前我们介绍的ProxyFactory我们知道,Spring ...

  4. 数据链路层学习之LLDP

    数据链路层学习之LLDP 2013年09月02日 20:38:36 goodluckwhh 阅读数 42323   一.LLDP协议概述 随着网络技术的发展,接入网络的设备的种类越来越多,配置越来越复 ...

  5. WordPress的Bootstrap面包屑导航

    <ol class="breadcrumb"> 当前位置: <li><a href="<?php bloginfo('url'); ? ...

  6. 学习笔记:yaml语言教程

    目录 1.YAML基本概念 1.1 简介 1.2 基本语法 1.3 支持的数据结构: 1.4 注意点 2.数据结构 2.1 字典 2.2 数组 2.3 纯量 2.4 强制类型转换,双! 2.5 字符串 ...

  7. 滑动窗口协议(Sliding Window Protocol)

    滑动窗口协议(Sliding Window Protocol),属于TCP协议的一种应用,用于网络数据传输时的流量控制,以避免拥塞的发生.该协议允许发送方在停止并等待确认前发送多个数据分组.由于发送方 ...

  8. Openssl 加解密文件

    使用openssl 的命令行进行文件的加密与解密过程,主要有两种方式: openssl 指定加密/解密算法加密 openssl 指定公钥/私钥文件加密 openssl 指定加密/解密算法加密 To E ...

  9. 【51nod】1407 与与与与

    [51nod]1407 与与与与 设\(f(x)\) 为\(A_{i} \& x == x\)的\(A_{i}\)的个数 设\(g(x)\)为\(x\)里1的个数 \(\sum_{i = 0} ...

  10. golang之map的使用声明

    1.map的基本介绍 map是key-value数据结构,又称为字段或者关联数组.类似其它编程语言的集合,在编程中是经常使用到的 2.map的声明 1)基本语法 var map 变量名 map[key ...