cf #422 c Hacker, pack your bags! 【贪心】
来源:互联网 发布:淘宝店铺主页封面 编辑:程序博客网 时间:2024/06/15 20:28
点击打开链接
题意:
一个人要去旅游,然后去旅行社看行程。
有n种走法,每种三个值, l,r,cost.
他原本有k金币。
分别代表出发日期,和归来日期,以及花费。
他想知道他能出行两次的最少花费是多少。不满足输出-1.
题解:
因为只要求出行两次,那么枚举中间值就行了,
枚举每个中间值,然后求出中间值之前的最小值,加中间值之后的最小值既是最优解。
#include<bits/stdc++.h>#define ll long longusing namespace std;const ll maxn=2e5+10;const ll inf=2e9+10;ll cost[maxn],day[maxn];ll dp[maxn];vector<ll> L[maxn],R[maxn];int main(){ ll n,k,l,r; scanf("%lld %lld",&n,&k); for(int i=1;i<=n;++i){ scanf("%lld %lld %lld",&l,&r,&cost[i]); day[i]=r-l+1; L[l].push_back(i); R[r].push_back(i); } for(ll i=1;i<=maxn;++i) dp[i]=inf; ll ans=inf; for(ll i=1;i<maxn;++i){ for(ll j=0;j<L[i].size();++j){ ll id=L[i][j]; ll x=k-day[id]; if(x<=0) continue; ans=min(ans,dp[x]+cost[id]); } for(ll j=0;j<R[i].size();++j){ ll id=R[i][j]; ll x=day[id]; dp[x]=min(dp[x],cost[id]); } } printf("%lld\n",(ans==inf)?-1:ans); return 0;}
阅读全文
0 0
- cf #422 c Hacker, pack your bags! 【贪心】
- cf C. Hacker, pack your bags!
- codeforces #422 C. Hacker, pack your bags!(贪心dp)
- Round 422 C. Hacker, pack your bags!
- Hacker, pack your bags!
- Codeforces Round #422 C. Hacker, pack your bags! (二分)
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags!
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags!
- CF422 div2 C. Hacker, pack your bags!
- codeforces 822 C Hacker, pack your bags!
- Codeforces822 C. Hacker, pack your bags!
- 822C Hacker, pack your bags!
- codeforces 882C Hacker, pack your bags!
- CodeForces 822C Hacker, pack your bags!
- 822C Hacker, pack your bags!
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序, 贪心, 暴力(居然可以n方暴力)
- codeforces Hacker, pack your bags!
- cf822c Hacker,Pack your bags
- 如何删除当前目录和子目录下的所有.log文件
- Cascade Classfication
- Android常用系统广播
- July Challenge 2017 | Calculator
- JAVA-1007. 素数对猜想 (20)
- cf #422 c Hacker, pack your bags! 【贪心】
- SQL Server CONVERT() 函数
- 【原创】ARM串口控制台
- 【UOJ228】基础数据结构练习题(线段树)
- Web自动化之Headless Chrome测试框架集成
- 记一次失败的小米面试
- AsyncTask简单的用法 点击加载图片
- leetcode 381. Insert Delete GetRandom O(1)
- 【面经笔记】红黑树的特性与其在C++ STL中的应用