CCPC 2016-2017 Finals
来源:互联网 发布:爽肤水怎么用 知乎 编辑:程序博客网 时间:2024/06/16 20:19
B-Wash
Mr.Panda is about to engage in his favourite activity doing laundry! He’s brought L indistinguishable loads of laundry to his local laundromat, which has N washing machines and M dryers.The ithith washing machine takes WiWi minutes to wash one load of laundry, and the ithith dryer takes Di minutes to dry a load of laundry.
At any point in time, each machine may only be processing at most one load of laundry.
As one might expect, Panda wants to wash and then dry each of his L loads of laundry. Each load of laundry will go through the following steps in order:
1. A non-negative amount of time after Panda arrives at the laundromat, Panda places the load in an unoccupied washing machine i.
2. Wi minutes later, he removes the load from the washing machine, placing it in a temporary holding basket (which has unlimited space)
3. A non-negative amount of time later, he places the load in an unoccupied dryer j
4. Dj minutes later, he removes the load from the dryer Panda can instantaneously add laundry to or remove laundry from a machine. Help Panda minimize the amount of time (in minutes after he arrives at the laundromat) after which he can be done washing and drying all L loads of laundry!
Input
The first line of the input gives the number of test cases, T.
T test cases follow. Each test case consists of three lines. The first line contains three integer L, N, and M.
The second line contains N integers W1,W2,…,WNW1,W2,…,WN representing the wash time of each wash machine.
The third line contains M integers D1,D2,…,DMD1,D2,…,DM representing the dry time of each dryer.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the minimum time it will take Panda to finish his laundry.
limits
∙1≤T≤100∙1≤T≤100. ∙1≤L≤106∙1≤L≤106. ∙1≤N,M≤105∙1≤N,M≤105. ∙1≤Wi,Di≤109∙1≤Wi,Di≤109.
Sample Input
21 1 11200342 3 2100 10 110 10
Sample Output
Case #1: 1234Case #2: 12
用优先队列优化的贪心。
分别算出每件衣服洗完和烘干的时间,纪做a[i])、b[i];
ans= ( a[i] + b[l-1-i] )的最大值;
C++提交TLE、G++就可以AC!!!
代码如下:
#include <algorithm>#include <bitset>#include <cassert>#include <climits>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <deque>#include <iomanip>#include <iostream>#include <map>#include <numeric>#include <queue>#include <set>#include <stack>#include <string>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;ll w[100010],d[100010],a[1000010],b[1000010];ll sum=0;ll l,n,m;typedef struct node{ ll cost,next; friend bool operator <(const node a,const node b){ return a.next>b.next; }}node;ll solve(){ priority_queue<node> que; for(ll i=0;i<n;i++){ node p={w[i],w[i]}; que.push(p); } for(ll i=0;i<l;i++){ node cur=que.top(); que.pop(); a[i]=cur.next; cur.next+=cur.cost; que.push(cur); } while(!que.empty()){ que.pop(); } for(ll i=0;i<m;i++){ node p={d[i],d[i]}; que.push(p); } ll ans=0; for(ll i=0;i<l;i++){ node cur=que.top(); que.pop(); b[i]=cur.next; cur.next+=cur.cost; que.push(cur); } for(ll i=0;i<l;i++){ ans=max(a[i]+b[l-i-1],ans); } return ans;}int main(){ int T,cases=0; cin>>T; while(T--){ memset(w,0,sizeof(w)); memset(d,0,sizeof(d)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); cases++; sum=0; // scanf("%lld%lld%lld",&l,&n,&m); for(int i=0;i<n;i++){ scanf("%lld",&w[i]); } for(int i=0;i<m;i++){ scanf("%lld",&d[i]); } printf("Case #%d: %lld\n",cases,solve()); } return 0;}
- CCPC 2016-2017 Finals
- CCPC 2016-2017, Finals (慢慢做,慢慢更新)
- 2016CCPC
- 2017 CCPC
- 2017CCPC秦皇岛 E:String of CCPC
- 2017 ccpc 秦皇岛E String of CCPC
- ACM-ICPC World Finals 2017
- 2016 ccpc网络赛
- 2016 ccpc 长春站
- 2016CCPC合肥总结
- 2016杭州ccpc
- 2016 ccpc 总决赛
- 2016 CCPC-Final A
- 2016 CCPC-Final B
- 【2016 CCPC-Final】B
- CCPC-final 2016 B
- hdu5965 2016CCPC
- 2017CCPC网络选拔赛
- 堆与栈
- Android--通过Intent使用Bundle如何传递对象
- MySQL 服务无法启动 或 启动慢
- C语言基础知识 梳理总结
- tar -zxvf 和 cp文件时报错
- CCPC 2016-2017 Finals
- 算法作业13
- HDU
- socket的accept函数解析
- Kingbase和PostgreSQL中如何查看当前连接的进程信息
- OpenCV 玩九宫格数独(二):knn 数字识别
- 论坛自动灌水(HTTP协议)--GET请求与POST请求的发送
- sizeof结构体
- IDEA激活码及webstorm