zoukankan      html  css  js  c++  java
  • POJ 3762 The Bonus Salary!

    The Bonus Salary!

    Time Limit: 2000ms
    Memory Limit: 65536KB
    This problem will be judged on PKU. Original ID: 3762
    64-bit integer IO format: %lld      Java class name: Main
     

    In order to encourage employees' productivity, ACM Company has made a new policy. At the beginning of a period, they give a list of tasks to each employee. In this list, each task is assigned a "productivity score". After the first K days, the employee who gets the highest score will be awarded bonus salary.

    Due to the difficulty of tasks, for task i-th:

    • It must be done from hh_Li mm_Li : ss_Li to hh_Ri : mm_Ri : ss_Ri.
    • This range of time is estimated very strictly so that anyone must use all of this time to finish the task.

    Moreover, at a moment, each employee can only do at most one task. And as soon as he finishes a task, he can start doing another one immediately.

    XYY is very hard-working. Unfortunately, he's never got the award. Thus, he asks you for some optimal strategy. That means, with a given list of tasks, which tasks he should do in the first K days to maximize the total productivity score. Notice that one task can be done at most once.

     

    Input

    The first line contains 2 integers N and K (1 ≤ N ≤ 2000, 0 ≤ K ≤ 100), indicating the number of tasks and days respectively. This is followed by N lines; each line has the following format:

    hh_Li:mm_Li:ss_Li hh_Ri:mm_Ri:ss_Ri w

    Which means, the i-th task must be done from hh_Li mm_Li : ss_Li to hh_Ri : mm_Ri : ss_Ri and its productivity score is w. (0 ≤hh_Lihh_Ri ≤ 23, 0 ≤mm_Limm_Riss_Liss_Ri≤ 59, 1 ≤ w ≤ 10000). We use exactly 2 digits (possibly with a leading zero) to represent hhmm and ss. It is guaranteed that the moment hh_Ri : mm_Ri : ss_Ri is strictly later thanhh_Li mm_Li : ss_Li. 

     

    Output

    The output only contains a nonnegative integer --- the maximum total productivity score.

     

    Sample Input

    5 2
    09:00:00 09:30:00 2
    09:40:00 10:00:00 3
    09:29:00 09:59:00 10
    09:30:00 23:59:59 4
    07:00:00 09:31:00 3
    

    Sample Output

    16

    Hint

    The optimal strategy is:
    Day1: Task1, Task 4
    Day2: Task 3
    The total productivity score is 2 + 4 + 10 = 16.

    解题:最小费用最大流。离散化时间点。

      1 #include <iostream>
      2 #include <cstdio>
      3 #include <cstring>
      4 #include <cmath>
      5 #include <algorithm>
      6 #include <climits>
      7 #include <vector>
      8 #include <queue>
      9 #include <cstdlib>
     10 #include <string>
     11 #include <set>
     12 #include <stack>
     13 #define LL long long
     14 #define pii pair<int,int>
     15 #define INF 0x3f3f3f3f
     16 using namespace std;
     17 const int maxn = 5010;
     18 struct arc{
     19     int v,w,f,next;
     20     arc(int x = 0,int y = 0,int z = 0,int nxt = 0){
     21         v = x;
     22         w = y;
     23         f = z;
     24         next = nxt;
     25     }
     26 };
     27 arc e[1000000];
     28 int head[maxn],d[maxn],p[maxn],tot,S,T;
     29 bool in[maxn];
     30 int n,m,lisan[maxn<<4],cnt,x[maxn],y[maxn],sc[maxn];
     31 void add(int u,int v,int w,int f){
     32     e[tot] = arc(v,w,f,head[u]);
     33     head[u] = tot++;
     34     e[tot] = arc(u,-w,0,head[v]);
     35     head[v] = tot++;
     36 }
     37 queue<int>q;
     38 bool spfa(){
     39     for(int i = S; i <= T; i++){
     40         d[i] = INF;
     41         p[i] = -1;
     42         in[i] = false;
     43     }
     44     while(!q.empty()) q.pop();
     45     d[S] = 0;
     46     in[S] = true;
     47     q.push(S);
     48     while(!q.empty()){
     49         int u = q.front();
     50         q.pop();
     51         in[u] = false;
     52         for(int i = head[u]; ~i; i = e[i].next){
     53             if(e[i].f > 0 && d[e[i].v] > d[u] + e[i].w){
     54                 d[e[i].v] = d[u] + e[i].w;
     55                 p[e[i].v] = i;
     56                 if(!in[e[i].v]){
     57                     in[e[i].v] = true;
     58                     q.push(e[i].v);
     59                 }
     60             }
     61         }
     62     }
     63     return p[T] > -1;
     64 }
     65 int solve(){
     66     int tmp = 0,minV;
     67     while(spfa()){
     68         minV = INF;
     69         for(int i = p[T]; ~i; i = p[e[i^1].v])
     70             minV = min(minV,e[i].f);
     71         for(int i = p[T]; ~i; i = p[e[i^1].v]){
     72             tmp += minV*e[i].w;
     73             e[i].f -= minV;
     74             e[i^1].f += minV;
     75         }
     76     }
     77     return tmp;
     78 }
     79 int main(){
     80     int hh,mm,ss;
     81     while(~scanf("%d %d",&n,&m)){
     82         tot = cnt = 0;
     83         memset(head,-1,sizeof(head));
     84         for(int i = 0; i < n; i++){
     85             scanf("%d:%d:%d",&hh,&mm,&ss);
     86             x[i] = hh*3600 + mm*60 + ss;
     87             lisan[cnt++] = x[i];
     88             scanf("%d:%d:%d",&hh,&mm,&ss);
     89             y[i] = hh*3600 + mm*60 + ss;
     90             lisan[cnt++] = y[i];
     91             scanf("%d",sc+i);
     92         }
     93         sort(lisan,lisan+cnt);
     94         int cnt1 = 1;
     95         for(int i = 1; i < cnt; i++)
     96         if(lisan[i] != lisan[cnt1-1]) lisan[cnt1++] = lisan[i];
     97         cnt = cnt1;
     98         S = 0;
     99         T = cnt;
    100         for(int i = 0; i < cnt; i++) add(i,i+1,0,m);
    101         for(int i = 0; i < n; i++){
    102             int tx = lower_bound(lisan,lisan+cnt,x[i]) - lisan;
    103             int ty = lower_bound(lisan,lisan+cnt,y[i]) - lisan;
    104             add(tx,ty,-sc[i],1);
    105         }
    106         printf("%d
    ",-solve());
    107     }
    108     return 0;
    109 }
    110 /*
    111 5 2
    112 09:00:00 09:30:00 2
    113 09:40:00 10:00:00 3
    114 09:29:00 09:59:00 10
    115 09:30:00 23:59:59 4
    116 07:00:00 09:31:00 3
    117 */
    View Code
  • 相关阅读:
    Oracle函数如何把符串装换为小写的格式
    Oralce中的synonym同义词
    JS中getYear()的兼容问题
    How to do SSH Tunneling (Port Forwarding)
    所谓深度链接(Deep linking)
    upload size of asp.net
    发一个自动刷网站PV流量的小工具
    解决Visual Studio 2008 下,打开.dbml(LINQ) 文件时,提示"The operation could not be completed." 的问题。
    在资源管理器中使鼠标右键增加一个命令,运行cmd,同时使得当前路径为资源管理器当前的目录
    使用SQL语句获取Sql Server数据库的版本
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3971910.html
Copyright © 2011-2022 走看看