Jury Meeting Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)(贪心,预处理?)
来源:互联网 发布:京东杜爽离职知乎 编辑:程序博客网 时间:2024/06/05 03:18
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.
There are n + 1 cities consecutively numbered from0 to n. City0 is Metropolis that is the meeting point for all jury members. For each city from1 to n there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requiresk days of work. For all of these k days each of the n jury members should be present in Metropolis to be able to work on problems.
You know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day.
Gather everybody for k days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for k days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than k days.
The first line of input contains three integers n,m and k (1 ≤ n ≤ 105,0 ≤ m ≤ 105,1 ≤ k ≤ 106).
The i-th of the following m lines contains the description of the i-th flight defined by four integersdi,fi,ti andci (1 ≤ di ≤ 106,0 ≤ fi ≤ n,0 ≤ ti ≤ n,1 ≤ ci ≤ 106, exactly one offi andti equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost.
Output the only integer that is the minimum cost of gathering all jury members in city0 for k days and then sending them back to their home cities.
If it is impossible to gather everybody in Metropolis for k days and then send them back to their home cities, output "-1" (without the quotes).
2 6 51 1 0 50003 2 0 55002 2 0 600015 0 2 90009 0 1 70008 0 2 6500
24500
2 4 51 2 0 50002 1 0 45002 1 0 30008 0 1 6000
-1
The optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day15, that would cost 2500 more.
In the second sample it is impossible to send jury member from city 2 back home from Metropolis.
题目大意:懒得说了
题目思路:这几场cf div2 d题都挺有趣的。。。。不过这一场abc题真是简单如狗,d题想清楚也是蛮水的,显然我是没想清楚,主要是这个贪心策略没想好,剩下真的是简单如狗,,,对于这道题,我们按照时间大小排序(想出这里,剩下的就很简单了),然后处理出满足条件的前缀和后缀最小值,相加找出最小值即可
ac代码:
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#define LL long long#define INF 0x3f3f3f3f3f3f3f3fusing namespace std;const int maxn = 1e5+5;struct node{ int d,f,t; LL c;}E[maxn];LL dp1[1000000+5];LL dp2[1000000+5];LL last[maxn];int vis[maxn];int n,m,k;int cmp(node a,node b){ return a.d<b.d;}int main(){ scanf("%d%d%d",&n,&m,&k); for(int i = 0;i<m;i++){ scanf("%d%d%d%I64d",&E[i].d,&E[i].f,&E[i].t,&E[i].c); } sort(E,E+m,cmp); memset(vis,0,sizeof(vis)); for(int i =0;i<=1000000+2;i++){ dp1[i] = INF; } int num = 0; LL sum = 0; for(int i = 0;i<m;i++){ if(E[i].f){ if(vis[E[i].f]==0){ num++; vis[E[i].f] = 1; last[E[i].f] = E[i].c; sum+=E[i].c; } else{ if(E[i].c<last[E[i].f]){ sum-=last[E[i].f]; sum+=E[i].c; last[E[i].f ] =E[i].c; } } } if(num==n){ dp1[E[i].d] = min(sum,dp1[E[i].d]); } } memset(vis,0,sizeof(vis)); for(int i = 0;i<=1000000+2;i++){ dp2[i] = INF; } sum = 0; num = 0; for(int i = m-1;i>=0;i--){ if(E[i].t){ if(vis[E[i].t]==0){ num++; vis[E[i].t] = 1; last[E[i].t] = E[i].c; sum+=E[i].c; } else{ if(E[i].c<last[E[i].t]){ sum-=last[E[i].t]; sum+=E[i].c; last[E[i].t ] =E[i].c; } } } if(num==n){ dp2[E[i].d] = min(sum,dp2[E[i].d]); // cout<<dp2[E[i].d]<<' '<<i<<endl; } } LL ans = INF; for(int i = 1;i<=1000000;i++){ dp1[i] = min(dp1[i],dp1[i-1]); } for(int i = 1000000;i>=1;i--){ dp2[i] = min(dp2[i],dp2[i+1]); } for(int i = 1;i<=1000000;i++){ if(i+k+1>1000000){ break; } /*if(dp2[i+k+1]<INF) cout<<dp1[i]<<' '<<dp2[i+k+1]<<endl;*/ ans = min(dp1[i]+dp2[i+k+1],ans); } if(ans>=INF) puts("-1"); else printf("%I64d\n",ans);}
- Jury Meeting Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)(贪心,预处理?)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(贪心)
- Codeforces Round #433(Div. 1,based on Olympiad of Metropolises)A Planning B Jury Meeting C Boredom
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A. Fraction
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B. Maxim Buys an Apartment
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)题解
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C Planning
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A,B,C
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A—C题解
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)C. Planning
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning(并查集)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) ABC
- Codeforces Round #433 (Div. 1, based on Olympiad of Metropolises) C. Boredom
- Java基础4:类加载过程
- 使用 vue-cli 搭建项目
- Centos 7 Apache配置虚拟主机
- 数字取整或保留小数四舍五入的正确写法
- python文件运行报错:UnboundLocalError: local variable 'status' referenced before assignment
- Jury Meeting Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)(贪心,预处理?)
- 【Android笔记-异常-5】Error:(1, 0) Minimum supported Gradle version is 3.3. Current version is 2.14.1.
- Vue 爬坑之路(二)—— 组件之间的数据传递
- halcon程序生成C++代码相关配置
- 【Git黑科技】git 删除远程分支上的某次commit
- hdu 3573 Buy Sticks(数学)
- unity 录音并保存本地
- 【转】C++ 常用的STL查找函数方法
- poj 1185 炮兵布阵 状压dp