CodeForces 822C Hacker, pack your bags!
题意
给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为x且代价最低
思路
相同持续时间的放在一个vector中,内部再对起始时间排序,从后向前扫获取对应起始时间的最优代价,存在minn中,对时间 i 从前向后扫,在对应的k-i中二分找第一个不重合的区间,其对应的minn加上 i 的cost即为出发时间为 i 时的最优解
代码
- #include<bits/stdc++.h>
- using namespace std;
- int n, k;
- struct EVE{
- int st,ed,val;
- EVE(){
- }
- EVE(int a,int b, int c){
- st = a, ed = b, val = c;
- }
- };
- int f,t,c;
- vector<EVE> v[];
- vector<int> minn[];
- int tmp[];
- bool cmp(EVE a, EVE b){
- return a.st<b.st;
- }
- int main(){
- scanf("%d%d",&n,&k);
- for(int i = ;i<n;i++){
- scanf("%d%d%d",&f,&t,&c);
- if(t-f+ >= k) continue;
- v[t-f+].push_back({f,t,c});
- }
- for(int i = ;i<=k;i++) sort(v[i].begin(),v[i].end(),cmp);
- for(int i = ;i<=k;i++){
- for(int j = v[i].size()-;j>=;j--){
- if(j==v[i].size()-) tmp[j]=v[i][j].val;
- else tmp[j]=min(v[i][j].val,tmp[j+]);
- }
- for(int j = ;j<v[i].size();j++){
- minn[i].push_back(tmp[j]);
- }
- }
- long long ans = 1e12;
- for(int i = ;i<=k;i++){
- if(v[k-i].empty()) continue;
- for(int j = ;j<v[i].size();j++){
- int ed = v[i][j].ed;
- long long cost = v[i][j].val;
- int le = , ri = v[k-i].size()-;
- if(v[k-i][ri].st<=ed) continue;
- int mid = le+ri>>;
- while(le<ri){
- mid = le+ri>>;
- if(v[k-i][mid].st<=ed) le = mid+;
- else ri = mid;
- }
- ans = min(ans, cost+minn[k-i][le]);
- }
- }
- if(ans == 1e12) printf("-1");
- else printf("%I64d",ans);
- return ;
- }
CodeForces 822C Hacker, pack your bags!的更多相关文章
- 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 ...
- 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 ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- 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 ...
- 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 ...
- CF822C Hacker, pack your bags!(思维)
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...
- 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 ...
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- codeforces 822 C. Hacker, pack your bags!(思维+dp)
题目链接:http://codeforces.com/contest/822/submission/28248100 题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加 ...
随机推荐
- laravel门面DB返回数组配置
在数据库配置文件中添加 'fetch' => PDO::FETCH_ASSOC, //但是这个配置好像是全局的,不能针对单个数据库连接进行配置 也可以在方法内使用php内置函数get_objec ...
- 【Leetcode_easy】784. Letter Case Permutation
problem 784. Letter Case Permutation 参考 1. Leetcode_easy_784. Letter Case Permutation; 2. Grandyang; ...
- Spring Aop(十五)——Aop原理之Advised接口
转发地址:https://www.iteye.com/blog/elim-2398726 Spring Aop原理之Advised接口 通过之前我们介绍的ProxyFactory我们知道,Spring ...
- 数据链路层学习之LLDP
数据链路层学习之LLDP 2013年09月02日 20:38:36 goodluckwhh 阅读数 42323 一.LLDP协议概述 随着网络技术的发展,接入网络的设备的种类越来越多,配置越来越复 ...
- WordPress的Bootstrap面包屑导航
<ol class="breadcrumb"> 当前位置: <li><a href="<?php bloginfo('url'); ? ...
- 学习笔记:yaml语言教程
目录 1.YAML基本概念 1.1 简介 1.2 基本语法 1.3 支持的数据结构: 1.4 注意点 2.数据结构 2.1 字典 2.2 数组 2.3 纯量 2.4 强制类型转换,双! 2.5 字符串 ...
- 滑动窗口协议(Sliding Window Protocol)
滑动窗口协议(Sliding Window Protocol),属于TCP协议的一种应用,用于网络数据传输时的流量控制,以避免拥塞的发生.该协议允许发送方在停止并等待确认前发送多个数据分组.由于发送方 ...
- Openssl 加解密文件
使用openssl 的命令行进行文件的加密与解密过程,主要有两种方式: openssl 指定加密/解密算法加密 openssl 指定公钥/私钥文件加密 openssl 指定加密/解密算法加密 To E ...
- 【51nod】1407 与与与与
[51nod]1407 与与与与 设\(f(x)\) 为\(A_{i} \& x == x\)的\(A_{i}\)的个数 设\(g(x)\)为\(x\)里1的个数 \(\sum_{i = 0} ...
- golang之map的使用声明
1.map的基本介绍 map是key-value数据结构,又称为字段或者关联数组.类似其它编程语言的集合,在编程中是经常使用到的 2.map的声明 1)基本语法 var map 变量名 map[key ...