codeforces 854 D. Jury Meeting(dp水题)
来源:互联网 发布:仙界淘宝店 编辑:程序博客网 时间:2024/06/05 20:14
题目链接
D. Jury Meeting
分析
昨晚打正式赛的时候太急了,代码写的有点毒,下了课后一看,立马发现bug…..
将去的航班表和返回航班表分别按照时间最小和最大排序,对于去的航班来说,挨个扫描过去,对每一个人维护当前的最小花费,若时间总的航班满足等于
对与返程航班也这样干就行了,计算出可以作为返回时间点的最小花费
对两个dp数组分别求到目前为止的最小花费,如
ac code
#include<bits/stdc++.h>#define pb push_back#define mp make_pair#define PI acos(-1)#define fi first#define se second#define INF 0x3f3f3f3f#define INF64 0x3f3f3f3f3f3f3f3f#define random(a,b) ((a)+rand()%((b)-(a)+1))#define ms(x,v) memset((x),(v),sizeof(x))#define scint(x) scanf("%d",&x );#define scf(x) scanf("%lf",&x );#define eps 1e-10#define dcmp(x) (fabs(x) < eps? 0:((x) <0?-1:1))#define lc o<<1#define rc o<<1|1using namespace std;typedef long long LL;typedef long double DB;typedef pair<int,int> Pair;const int maxn = 1e6+10;const int MAX_V= 500+10;const int MOD = 998244353;struct day{ int d,cost,num; bool operator< (const day& o)const{ if(d != o.d)return d > o.d; else return cost > o.cost; }};day P[maxn],b[maxn];bool cmp(const day & a,const day & b){ if(a.d != b.d)return a.d >b.d; else return a.cost < b.cost;}int c[maxn],d[maxn];LL dp[maxn],dp1[maxn];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,k; cin>>n>>m>>k; int t1 =0; int t2 =0; for(int i=1 ; i<maxn ; ++i) dp[i] = INF64,c[i] = 0,dp1[i] = INF64,d[i]=0; priority_queue<day> Q; for(int i=1 ; i<=m ; ++i){ int d,u,v,cost;cin>>d>>u>>v>>cost; if(u)Q.push(day{d,cost,u}); else P[t2++] = day{d,cost,v}; } sort(P,P+t2,cmp); int tot =0; LL ans =0; while (!Q.empty()) { day p = Q.top();Q.pop(); int u = p.num; if(!c[u])c[u] = p.cost,tot++,ans += c[u]; else if( c[u]> p.cost) ans += p.cost - c[u],c[u] = p.cost; if(tot == n)dp[p.d] = min(dp[p.d],ans); } tot =0; ans =0; for(int i = 0 ; i<t2 ; ++i){ day p = P[i]; int v = p.num; if(!d[v])d[v] = p.cost,tot++,ans += d[v]; else if(d[v] > p.cost) ans += p.cost - d[v],d[v] = p.cost; if(tot == n)dp1[p.d] = min(dp1[p.d],ans); } for(int i = 2 ; i<maxn ; ++i)dp[i] = min(dp[i],dp[i-1]); //std::cout << maxn << '\n'; for(int i = maxn -2 ; i>=0 ; --i){ dp1[i] = min(dp1[i],dp1[i+1]); } ans = INF64; for(int i=1 ; i<maxn -k-1; ++i){ ans = min(ans , dp[i]+ dp1[i+k+1]); } // for(int i=1 ; i<20 ; ++i){ // std::cout << dp[i]<<" " << dp1[i] << '\n'; // } if(ans == INF64)std::cout << -1 << '\n'; else std::cout << ans << '\n'; //std::cout << "time "<< clock()/1000 <<"ms"<< '\n'; return 0;}
阅读全文
0 0
- codeforces 854 D. Jury Meeting(dp水题)
- Codeforces 854 D. Jury Meeting(技巧)
- Codeforces 854D Jury Meeting【思维+前后缀和+二分】
- Codeforces 854 D Jury Meeting(前缀和后缀)
- [codeforces] 854D. Jury Meeting(前/后缀最小值)
- codeforces 854D Jury Meeting (思维、尺取)
- Codeforces Round #433 D. Jury Meeting
- codeforces 845D Jury Meeting(div.2)
- Codeforces Round #433 D. Jury Meeting
- Jury Meeting CodeForces
- CF853B Jury Meeting(dp)
- Codeforces Round #433Div. 2 D Jury Meeting 优先队列
- Codeforces Round #433 (Div. 2) D. Jury Meeting
- Codeforces Round #433 (Div. 2 D. Jury Meeting 二分
- Codeforces Round #433 (Div. 2) D. Jury Meeting
- Codeforces Round #433 Jury Meeting
- Codeforces Round #433 (Div. 2) D. Jury Meeting(思维 贪心 前后缀)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(贪心)
- java面向对象知识点
- Docker 学习系列--镜像
- Leetcode463. Island Perimeter
- 框架中的单入口和多入口
- 使用Git提交文件/代码到码云
- codeforces 854 D. Jury Meeting(dp水题)
- 微型 ORM-FluentData 实例详解
- IntelliJ Idea 2017激活破解方法
- tslib移植
- MySQL查询指定数据库指定表是否被加锁
- CentOS7 安装MySQL 5.7
- XSS攻击
- 描述员工信息的简易办公信息化管理系统
- 一、常量