Teamwork

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 497 Accepted Submission(s): 258

Problem Description
Some locations in city A has been destroyed in the fierce battle. So the government decides to send some workers to repair these locations. There are m kinds of workers that were trained for different skills. Each location need some number of some kinds of workers and has a schedule that at what time can the repair begins, and the time cost of repair. Any job cannot begin until all the workers required arrived.
For example, location 1 needs 2 workers of type 1 and 3 workers of type 2, and the beginning time and time cost is 100 minute and 90 minute correspondingly, then 5 workers that satisfy the requirement should arrive before 100 minute, start working at 100 minute and get the job done at 190 minute. Notice that two different types of workers cannot replace each other, so with 3 workers of type 1 and only 2 workers of type 2, this job cannot be done.
Workers can go from one location to another after their jobs are done. You can take the Euclidean distance between locations as the time workers need to travel between them. Each worker should be sent from a depot initially at 0 minute. Now your task is to determine the minimum number of workers needed to be sent from depot so that all the jobs can be done.

Input
There are multiple test cases, the integer on the first line T (T<25) indicates the number of test cases.
Each test case begins with two integers n (<=150), the number of location(including the depot) and m(<=5), the number of different skills.
The next line gives two integers x0, y0 indicates the coordinate of depot.
Then follows n - 1 lines begins with 4 integer numbers: xi, yi, bi(bi>0), pi(pi>0), (xi, yi) gives the coordinate of the i-th location, bi gives the beginning time and pi gives the time cost. The rest of the line gives m non-negative integers v1, v2, ..., vm, of which the i-th number indicates the the number of workers of type i needed (for all vi, 0<=vi<10, each location at least requires one worker).
All integers are less than 1000000 (106).

Output
For each test cases output one line, the minimum workers to be sent. It is guaranteed that there's always a feasible solution that all the jobs can be done.

Sample Input
2
4 1
0 0
0 1 1 1 3
1 1 3 3 4
1 0 10 1 5
4 1
0 0
0 1 1 1 3
1 1 3 3 4
1 0 3 1 5

Sample Output
5
9

一开始不会,在网上找了一下,看到有一个博客里是这么说的:

没看明白他是什么意思,为什么要把一个点分成3个点。我拿第一组示例输入画了一下图:

  1是源点,3n+1是汇点,中间的3列是拆分之后的3组点。关键看第三列的点,它的流量有两个来源,一是从源点派出,费用是1,代表这部分工人是另行派出的;二是从其他节点派出,费用是0,代表这部分工人是完成其他任务后转来的。

  顺便,从图里可以看出,确实不用分成3个点,第一列完全没必要。这道题整理了一个最小费用流的模板--->

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<cstdio>
  6. using namespace std;
  7. const int Maxn = ;
  8. int n, m, k;
  9. int sta[Maxn], en[Maxn], ty[Maxn][];
  10. double d[Maxn][Maxn];
  11. struct Point {
  12. double x, y;
  13. } p[Maxn];
  14. double DIS(Point a, Point b) {
  15. return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
  16. }
  17. //ALGORITHM MINCOSTFLOW ->
  18. #define ALGORITHM_MINCOSTFLOW_MAXN 600
  19. #define ALGORITHM_MINCOSTFLOW_MAXM 360000
  20. #define ALGORITHM_MINCOSTFLOW_INF 0X7FFFFFFF
  21. struct ALGORITHM_MINCOSTFLOW_Edge {
  22. int v;
  23. int val;
  24. int cost;
  25. int next;
  26. } ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_MAXM];
  27. int ALGORITHM_MINCOSTFLOW_head[ALGORITHM_MINCOSTFLOW_MAXN];
  28. int ALGORITHM_MINCOSTFLOW_countedge;
  29. int ALGORITHM_MINCOSTFLOW_pre[ALGORITHM_MINCOSTFLOW_MAXN];
  30. int ALGORITHM_MINCOSTFLOW_pos[ALGORITHM_MINCOSTFLOW_MAXN];
  31. int ALGORITHM_MINCOSTFLOW_dis[ALGORITHM_MINCOSTFLOW_MAXN];
  32. int ALGORITHM_MINCOSTFLOW_que[ALGORITHM_MINCOSTFLOW_MAXM];
  33. bool ALGORITHM_MINCOSTFLOW_vis[ALGORITHM_MINCOSTFLOW_MAXN];
  34. void ALGORITHM_MINCOSTFLOW_addedge(int u, int v, int val, int cost) {
  35. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].v = v;
  36. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].val = val;
  37. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].cost = cost;
  38. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].next = ALGORITHM_MINCOSTFLOW_head[u];
  39. ALGORITHM_MINCOSTFLOW_head[u] = ALGORITHM_MINCOSTFLOW_countedge++;
  40. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].v = u;
  41. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].val = ;
  42. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].cost = -cost;
  43. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].next = ALGORITHM_MINCOSTFLOW_head[v];
  44. ALGORITHM_MINCOSTFLOW_head[v] = ALGORITHM_MINCOSTFLOW_countedge++;
  45. }
  46. void ALGORITHM_MINCOSTFLOW_clear() {
  47. memset(ALGORITHM_MINCOSTFLOW_head, -, sizeof(ALGORITHM_MINCOSTFLOW_head));
  48. ALGORITHM_MINCOSTFLOW_countedge = ;
  49. }
  50. bool ALGORITHM_MINCOSTFLOW_spfa(int s, int t) {
  51. memset(ALGORITHM_MINCOSTFLOW_pre, -, sizeof(ALGORITHM_MINCOSTFLOW_pre));
  52. memset(ALGORITHM_MINCOSTFLOW_vis, , sizeof(ALGORITHM_MINCOSTFLOW_vis));
  53. int Head, tail;
  54. Head = tail = ;
  55. for (int i = ; i < ALGORITHM_MINCOSTFLOW_MAXN; i++) {
  56. ALGORITHM_MINCOSTFLOW_dis[i] = ALGORITHM_MINCOSTFLOW_INF;
  57. }
  58. ALGORITHM_MINCOSTFLOW_que[tail++] = s;
  59. ALGORITHM_MINCOSTFLOW_pre[s] = s;
  60. ALGORITHM_MINCOSTFLOW_dis[s] = ;
  61. ALGORITHM_MINCOSTFLOW_vis[s] = ;
  62. while (Head != tail) {
  63. int now = ALGORITHM_MINCOSTFLOW_que[Head++];
  64. ALGORITHM_MINCOSTFLOW_vis[now] = ;
  65. for (int i = ALGORITHM_MINCOSTFLOW_head[now]; i != -; i = ALGORITHM_MINCOSTFLOW_edge[i].next) {
  66. int adj = ALGORITHM_MINCOSTFLOW_edge[i].v;
  67. if (ALGORITHM_MINCOSTFLOW_edge[i].val > && ALGORITHM_MINCOSTFLOW_dis[now] + ALGORITHM_MINCOSTFLOW_edge[i].cost < ALGORITHM_MINCOSTFLOW_dis[adj]) {
  68. ALGORITHM_MINCOSTFLOW_dis[adj] = ALGORITHM_MINCOSTFLOW_dis[now] + ALGORITHM_MINCOSTFLOW_edge[i].cost;
  69. ALGORITHM_MINCOSTFLOW_pre[adj] = now;
  70. ALGORITHM_MINCOSTFLOW_pos[adj] = i;
  71. if (!ALGORITHM_MINCOSTFLOW_vis[adj]) {
  72. ALGORITHM_MINCOSTFLOW_vis[adj] = ;
  73. ALGORITHM_MINCOSTFLOW_que[tail++] = adj;
  74. }
  75. }
  76. }
  77. }
  78. return ALGORITHM_MINCOSTFLOW_pre[t] != -;
  79. }
  80. int ALGORITHM_MINCOSTFLOW_MinCostFlow(int s, int t) {
  81. int cost = , flow = ;
  82. while (ALGORITHM_MINCOSTFLOW_spfa(s, t)) {
  83. int f = ALGORITHM_MINCOSTFLOW_INF;
  84. for (int i = t; i != s; i = ALGORITHM_MINCOSTFLOW_pre[i])
  85. if (ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i]].val < f) {
  86. f = ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i]].val;
  87. }
  88. flow += f;
  89. cost += ALGORITHM_MINCOSTFLOW_dis[t] * f;
  90. for (int i = t; i != s; i = ALGORITHM_MINCOSTFLOW_pre[i]) {
  91. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i]].val -= f;
  92. ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i] ^ ].val += f;
  93. }
  94. }
  95. return cost;
  96. }
  97. // <- ALGORITHM MINCOSTFLOW
  98. void build(int type) {
  99. int i, j;
  100. ALGORITHM_MINCOSTFLOW_clear();
  101. for (i = ; i <= n; i++) {
  102. ALGORITHM_MINCOSTFLOW_addedge(, i + * n, ty[i][type], );
  103. ALGORITHM_MINCOSTFLOW_addedge(, i + n, ty[i][type], );
  104. ALGORITHM_MINCOSTFLOW_addedge(i + * n, * n + , ty[i][type], );
  105. for (j = ; j <= n; j++) {
  106. if (sta[i] + en[i] + d[i][j] <= sta[j]) {
  107. ALGORITHM_MINCOSTFLOW_addedge(i + n, j + * n, ty[i][type], );
  108. }
  109. }
  110. }
  111. }
  112. int solve() {
  113. int i, j, u, v;
  114. int ans = ;
  115. for (i = ; i <= m; i++) {
  116. build(i);
  117. ans += ALGORITHM_MINCOSTFLOW_MinCostFlow(, * n + );
  118. }
  119. return ans;
  120. }
  121. int main() {
  122. int i, j, u, v, c, t;
  123. scanf("%d", &t);
  124. while (t--) {
  125. ALGORITHM_MINCOSTFLOW_clear();
  126. scanf("%d%d", &n, &m);
  127. scanf("%lf%lf", &p[].x, &p[].y);
  128. for (i = ; i <= n; i++) {
  129. scanf("%lf%lf%d%d", &p[i].x, &p[i].y, &sta[i], &en[i]);
  130. for (j = ; j <= m; j++) {
  131. scanf("%d", &ty[i][j]);
  132. }
  133. }
  134. for (i = ; i <= n; i++) {
  135. for (j = i + ; j <= n; j++) {
  136. d[i][j] = d[j][i] = DIS(p[i], p[j]);
  137. }
  138. }
  139. printf("%d\n", solve());
  140. }
  141. return ;
  142. }

Teamwork[HDU4494]的更多相关文章

  1. hdu 4494 Teamwork 最小费用最大流

    Teamwork Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4494 ...

  2. Scrum And Teamwork

    Scrum Learning 概念 Scrum是迭代式增量软件开发过程,通常用于敏捷软件开发.Scrum包括了一系列实践和预定义角色的过程骨架.Scrum中的主要角色包括同项目经理类似的Scrum主管 ...

  3. GIT TEAMWORK

    Learn GIT TEAMWORK generalizations Congratulations, you now know enough to start collaborating on Gi ...

  4. CSUOJ 1525 Algebraic Teamwork

    Problem A Algebraic Teamwork The great pioneers of group theory and linear algebra want to cooperate ...

  5. P5124 Teamwork(DP)

    题目: P5124 [USACO18DEC]Teamwork 解析: 动态规划,设\(f[i]\)表示到第\(i\)位的最大值,我们枚举i之前的j个位置\((j<k)\),记录一下这\(j+1\ ...

  6. 2019 GDUT Rating Contest I : Problem B. Teamwork

    题面: 传送门 B. Teamwork Input file: standard input Output file: standard output Time limit: 1 second Memor ...

  7. Teamwork——Week4 团队分工和预估项目时间

    由于我们给每个组员预估的每天用在该团队项目的时间为2h左右,因此我们的时间计算也已2h为基数.下面就是我们的团队分工和预估项目时间. 任务编号 实现人员 任务详细描述 预估时间 任务0 全体组员 看学 ...

  8. Teamwork——Week 4 Daily Scrum Meeting#1 2013.10.23

    一.会议议题 1)根据确立的项目题目,进一步明确PM,DEV,TEST的工作. 2)确定团队分工和预估项目时间. 3)完成项目架构NABC模型. 4)确定第一轮开发团队分工 二.会议时间 2013年1 ...

  9. Teamwork——Week4 团队项目之NABC

    项目框架——NABC模型 一.N(Need需求) 我们组主要的用户对象是第三小组——UI小组的同学们,因此我们的用户需求就是他们的数据需求. 1)提供给UI小组整理好的数据库,和前一组讨论好数据结构. ...

随机推荐

  1. 使用Gson送解析Json格式

    Java bean: package com.jingle.a; public class Person { public String name; public int age; public Pe ...

  2. Swift - 让程序挂起后,能在后台继续运行任务

    1,程序的挂起和退出 由于iOS设备资源有限.当用户点击了home键,或者另一个应用程序启动了.那么原先那个程序便进入后台被挂起,不是退出,只是停止执行代码,同时它的内存被锁定.当应用程序恢复时,它会 ...

  3. 常用iOS的第三方框架

    图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等 ...

  4. Android -- getQuantityString无效

    原文:http://www.xuebuyuan.com/1510993.html 原因:中文没有复数语法.

  5. .net学习之Attribute特性和EF关键知识点

    一.Attribute特性/标签1.Attribute用来对类.属性.方法等标注额外的信息,贴一个标签简单的说,定制特性Attribute,本质上就是一个类,它为目标元素提供关联附加信息,并在运行时以 ...

  6. 重温WCF之消息拦截与篡改(八)

    我们知道,在WCF中,客户端对服务操作方法的每一次调用,都可以被看作是一条消息,而且,可能我们还会有一个疑问:如何知道客户端与服务器通讯过程中,期间发送和接收的SOAP是什么样子.当然,也有人是通过借 ...

  7. yaf框架使用(centos6.5)

    安装好php环境之后 安装扩展包 $yum install php-devel /usr/bin/ 就会出现phpize工具包 下载yaf-2.2.8.gz源文件,解压后,进入源文件 phpize [ ...

  8. android 入门-android属性介绍

      android:visibility="gone" 不保留view控件所占有的空间 隐藏 android:visibility="invisible" 保留 ...

  9. php array_intersect() 和 array_diff() 函数

    在PHP中,使用 array_intersect 求两个数组的交集比使用 array_diff 求同样两个数组的并集要快. 如果要求数组 $a 与数组 $b 的差集的个数,应该使用 count($a) ...

  10. hdu 4023 2011上海赛区网络赛C 贪心+模拟

    以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 #include<cstdio> #include<iostream> #include<algori ...