codeforces 822 C. Hacker, pack your bags!(思维+dp)
题目链接:http://codeforces.com/contest/822/submission/28248100
题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加一个标记就知道这是开始区间还是结束区间具体看一下代码。
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define inf 1000000000000
using namespace std;
const int M = 2e5 + 10;
typedef long long ll;
struct TnT {
int sta , cau , flag;
ll val;
}a[M << 1];
bool cmp(TnT x , TnT y) {
if(x.sta == y.sta) return x.flag > y.flag;
return x.sta < y.sta;
}
ll dp[M];//dp[i]存储之前状态区间长度为i的最小花费
int main() {
int n;
ll x;
scanf("%d%lld" , &n , &x);
int cnt = 0;
for(int i = 0 ; i < n ; i++) {
int l , r;
ll c;
scanf("%d%d%lld" , &l , &r , &c);
a[cnt].sta = l , a[cnt].flag = 1 , a[cnt].cau = r - l + 1 , a[cnt].val = c;
a[++cnt].sta = r , a[cnt].flag = -1 , a[cnt].cau = r - l + 1 , a[cnt].val = c;
cnt++;
}
sort(a , a + cnt , cmp);
for(int i = 0 ; i < M ; i++) dp[i] = inf;
ll ans = inf;
for(int i = 0 ; i < cnt ; i++) {
if(a[i].flag == 1) {
ll sum = x - a[i].cau;
if(sum >= 0) {
if(dp[sum] < inf) ans = min(ans , a[i].val + dp[sum]);
}
}
else {
dp[a[i].cau] = min(dp[a[i].cau] , a[i].val);
}//这里的标记决定了dp是否要更新,显然在区间结束时就可以更新dp了
}
if(ans < inf) printf("%lld\n" , ans);
else printf("-1\n");
return 0;
}
codeforces 822 C. Hacker, pack your bags!(思维+dp)的更多相关文章
- CF822C Hacker, pack your bags!(思维)
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- CF-822C Hacker, pack your bags! 思维题
题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚 ...
- 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 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 ...
- 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 ...
- 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 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 Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
随机推荐
- 简易数据分析 08 | Web Scraper 翻页——点击「更多按钮」翻页
这是简易数据分析系列的第 8 篇文章. 我们在Web Scraper 翻页--控制链接批量抓取数据一文中,介绍了控制网页链接批量抓取数据的办法. 但是你在预览一些网站时,会发现随着网页的下拉,你需要点 ...
- Maven安装和配置环境变量
Maven配置 1.下载 下载maven 3.5.4 先到官网http://maven.apache.org/download.cgi 下载最新版本(目前是3.5.4 ),下载完成后,解压到某个目录( ...
- 【vue】------ 路由创建 ------ 【William】
路由常用的配置项: path:路由请求的路径 component:路由匹配成功后需要渲染的组件或者页面 tag:改变组件内部渲染的元素 假设组件内部渲染的是a标签 tag="li" ...
- Redis优化建议
优化的一些建议 1.尽量使用短的key 当然在精简的同时,不要完了key的"见名知意".对于value有些也可精简,比如性别使用0.1. 2.避免使用keys * keys *, ...
- 【JDK】JDK源码分析-AbstractQueuedSynchronizer(2)
概述 前文「JDK源码分析-AbstractQueuedSynchronizer(1)」初步分析了 AQS,其中提到了 Node 节点的「独占模式」和「共享模式」,其实 AQS 也主要是围绕对这两种模 ...
- feign传输String json串 自动转义 \ 解决方法
@RequestMapping(value={"/sysOrgRest/getInfoByOrgIds"}, method={org.springframework.web.bin ...
- 【Java笔记】【Java核心技术卷1】chapter3 D5运算符
package chapter3; import java.math.*; //引入数学类 //枚举类型 enum Size{SMALL,MEDIUM,LARGE}; public class D5运 ...
- Android使用com.google.android.cameraview.CameraView进行拍照
import android.Manifest;import android.annotation.SuppressLint;import android.content.Context;import ...
- Maven安装配置及其插件m2e(Eclipse Indigo 和 MyEclipse8.5)的安装配置
Maven安装配置及其插件m2e(Eclipse Indigo 和 MyEclipse8.5)的安装配置 系统:Windows7 使用软件: Maven3.0.3 + Eclipse Indigo ...
- Docker入门-搭建docker私有仓库
Docker Hub 目前Docker官方维护了一个公共仓库Docker Hub,其中已经包括了数量超过15000个镜像.大部分需求都可以通过在Docker Hub中直接下载镜像来使用. 注册登录 可 ...