codeforces 845D Jury Meeting(div.2)
来源:互联网 发布:淘宝转化率40算正常吗 编辑:程序博客网 时间:2024/05/22 18:11
思路:
- 票按时间升序排序
- 正着扫一遍得到start[i],表示会议从第i天开始,到达的人的花费,大于初始化值表示人未到齐
- 反着扫一遍得到end[i],表示第i天已回家的人的花费,大于初始化值表示人未全回
- 枚举会议开始的那一天 i ,则
ans=min(ans,start[i]+end[i+k+1])
代码:
#include <iostream>#include <cmath>#include <cstdio>#include <cstring>#include <bits/stdc++.h>using namespace std;const int MAXN = 1e6+7;const int MAXM = 1e5+7;const int INF = 0x3fff3fff;const double eps=1e-6;typedef long long LL;int n,m,k;struct P{ int day,u,v,cost; bool operator < (const P &x)const{ if(day!=x.day)return day<x.day; else return cost-x.cost; }};P a[MAXN];LL a2[MAXN],b[MAXN];LL cost[MAXN];int main(){ while(cin>>n>>m>>k){ for(int i=0;i<m;i++){ P tmp; scanf("%d%d%d%d",&tmp.day,&tmp.u,&tmp.v,&tmp.cost); a[i]=tmp; } sort(a,a+m); for(int i=0;i<MAXN;i++)cost[i]=1e12; int cc=0; LL now=0; for(int i=0;i<n;i++)now+=cost[i]; for(int i=0;i<MAXN;i++){ while(cc<m&&a[cc].day==i){ if(a[cc].v==0&&a[cc].cost<cost[a[cc].u]) now+=a[cc].cost-cost[a[cc].u],cost[a[cc].u]=a[cc].cost; cc++; } a2[i]=now; } for(int i=0;i<MAXN;i++)cost[i]=1e12; cc=m-1; now=0; for(int i=0;i<n;i++)now+=cost[i]; for(int i=MAXN-1;i>=0;i--){ while(cc>=0&&a[cc].day==i){ if(a[cc].u==0&&a[cc].cost<cost[a[cc].v]) now+=a[cc].cost-cost[a[cc].v],cost[a[cc].v]=a[cc].cost; cc--; } b[i]=now; } LL ans=1e18; for(int i=0;i<MAXN-k-1;i++)ans=min(ans,a2[i]+b[i+k+1]);//,cout<<a[i].day<<endl; ans>1e12?cout<<-1<<endl:cout<<ans<<endl; } return 0;}
阅读全文
0 0
- codeforces 845D Jury Meeting(div.2)
- 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 (Div. 2) D. Jury Meeting(思维 贪心 前后缀)
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(贪心)
- Codeforces Round #433 (Div. 2) Jury Meeting(贪心)
- Codeforces Round #433 (Div. 2,) Jury Meeting 贪心 + 技巧
- Codeforces Round #433 D. Jury Meeting
- codeforces 854 D. Jury Meeting(dp水题)
- Codeforces Round #433 D. Jury Meeting
- Codeforces 854 D. Jury Meeting(技巧)
- Jury Meeting CodeForces
- Jury Meeting Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)(贪心,预处理?)
- Codeforces Round #433 (Div. 1) B Jury Meeting(思维)
- Codeforces 854D Jury Meeting【思维+前后缀和+二分】
- Codeforces 854 D Jury Meeting(前缀和后缀)
- mysql启动问题修复
- poj 1936
- Qt按键插件、触摸屏插件不起作用的解决办法及自定义插件编译
- 关于屏幕适配的一些理解
- Java内部类详解
- codeforces 845D Jury Meeting(div.2)
- 欢迎使用CSDN-markdown编辑器
- 设置MySQL远程登录
- Java四种线程池的使用
- 【概念】SOA和微服务
- 深度学习的seq2seq模型
- JAVA 各种概念
- Webstorm安装Less
- 函数的注册与回调【经验】