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个点,第一列完全没必要。这道题整理了一个最小费用流的模板--->

#include<iostream>
#include<cstring>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
const int Maxn = ;
int n, m, k;
int sta[Maxn], en[Maxn], ty[Maxn][];
double d[Maxn][Maxn];
struct Point {
double x, y;
} p[Maxn];
double DIS(Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
//ALGORITHM MINCOSTFLOW ->
#define ALGORITHM_MINCOSTFLOW_MAXN 600
#define ALGORITHM_MINCOSTFLOW_MAXM 360000
#define ALGORITHM_MINCOSTFLOW_INF 0X7FFFFFFF
struct ALGORITHM_MINCOSTFLOW_Edge {
int v;
int val;
int cost;
int next;
} ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_MAXM];
int ALGORITHM_MINCOSTFLOW_head[ALGORITHM_MINCOSTFLOW_MAXN];
int ALGORITHM_MINCOSTFLOW_countedge;
int ALGORITHM_MINCOSTFLOW_pre[ALGORITHM_MINCOSTFLOW_MAXN];
int ALGORITHM_MINCOSTFLOW_pos[ALGORITHM_MINCOSTFLOW_MAXN];
int ALGORITHM_MINCOSTFLOW_dis[ALGORITHM_MINCOSTFLOW_MAXN];
int ALGORITHM_MINCOSTFLOW_que[ALGORITHM_MINCOSTFLOW_MAXM];
bool ALGORITHM_MINCOSTFLOW_vis[ALGORITHM_MINCOSTFLOW_MAXN];
void ALGORITHM_MINCOSTFLOW_addedge(int u, int v, int val, int cost) {
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].v = v;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].val = val;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].cost = cost;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].next = ALGORITHM_MINCOSTFLOW_head[u];
ALGORITHM_MINCOSTFLOW_head[u] = ALGORITHM_MINCOSTFLOW_countedge++;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].v = u;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].val = ;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].cost = -cost;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_countedge].next = ALGORITHM_MINCOSTFLOW_head[v];
ALGORITHM_MINCOSTFLOW_head[v] = ALGORITHM_MINCOSTFLOW_countedge++;
}
void ALGORITHM_MINCOSTFLOW_clear() {
memset(ALGORITHM_MINCOSTFLOW_head, -, sizeof(ALGORITHM_MINCOSTFLOW_head));
ALGORITHM_MINCOSTFLOW_countedge = ;
}
bool ALGORITHM_MINCOSTFLOW_spfa(int s, int t) {
memset(ALGORITHM_MINCOSTFLOW_pre, -, sizeof(ALGORITHM_MINCOSTFLOW_pre));
memset(ALGORITHM_MINCOSTFLOW_vis, , sizeof(ALGORITHM_MINCOSTFLOW_vis));
int Head, tail;
Head = tail = ;
for (int i = ; i < ALGORITHM_MINCOSTFLOW_MAXN; i++) {
ALGORITHM_MINCOSTFLOW_dis[i] = ALGORITHM_MINCOSTFLOW_INF;
}
ALGORITHM_MINCOSTFLOW_que[tail++] = s;
ALGORITHM_MINCOSTFLOW_pre[s] = s;
ALGORITHM_MINCOSTFLOW_dis[s] = ;
ALGORITHM_MINCOSTFLOW_vis[s] = ;
while (Head != tail) {
int now = ALGORITHM_MINCOSTFLOW_que[Head++];
ALGORITHM_MINCOSTFLOW_vis[now] = ;
for (int i = ALGORITHM_MINCOSTFLOW_head[now]; i != -; i = ALGORITHM_MINCOSTFLOW_edge[i].next) {
int adj = ALGORITHM_MINCOSTFLOW_edge[i].v;
if (ALGORITHM_MINCOSTFLOW_edge[i].val > && ALGORITHM_MINCOSTFLOW_dis[now] + ALGORITHM_MINCOSTFLOW_edge[i].cost < ALGORITHM_MINCOSTFLOW_dis[adj]) {
ALGORITHM_MINCOSTFLOW_dis[adj] = ALGORITHM_MINCOSTFLOW_dis[now] + ALGORITHM_MINCOSTFLOW_edge[i].cost;
ALGORITHM_MINCOSTFLOW_pre[adj] = now;
ALGORITHM_MINCOSTFLOW_pos[adj] = i;
if (!ALGORITHM_MINCOSTFLOW_vis[adj]) {
ALGORITHM_MINCOSTFLOW_vis[adj] = ;
ALGORITHM_MINCOSTFLOW_que[tail++] = adj;
}
}
}
}
return ALGORITHM_MINCOSTFLOW_pre[t] != -;
}
int ALGORITHM_MINCOSTFLOW_MinCostFlow(int s, int t) {
int cost = , flow = ;
while (ALGORITHM_MINCOSTFLOW_spfa(s, t)) {
int f = ALGORITHM_MINCOSTFLOW_INF;
for (int i = t; i != s; i = ALGORITHM_MINCOSTFLOW_pre[i])
if (ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i]].val < f) {
f = ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i]].val;
}
flow += f;
cost += ALGORITHM_MINCOSTFLOW_dis[t] * f;
for (int i = t; i != s; i = ALGORITHM_MINCOSTFLOW_pre[i]) {
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i]].val -= f;
ALGORITHM_MINCOSTFLOW_edge[ALGORITHM_MINCOSTFLOW_pos[i] ^ ].val += f;
}
}
return cost;
}
// <- ALGORITHM MINCOSTFLOW
void build(int type) {
int i, j;
ALGORITHM_MINCOSTFLOW_clear();
for (i = ; i <= n; i++) {
ALGORITHM_MINCOSTFLOW_addedge(, i + * n, ty[i][type], );
ALGORITHM_MINCOSTFLOW_addedge(, i + n, ty[i][type], );
ALGORITHM_MINCOSTFLOW_addedge(i + * n, * n + , ty[i][type], );
for (j = ; j <= n; j++) {
if (sta[i] + en[i] + d[i][j] <= sta[j]) {
ALGORITHM_MINCOSTFLOW_addedge(i + n, j + * n, ty[i][type], );
}
}
}
}
int solve() {
int i, j, u, v;
int ans = ;
for (i = ; i <= m; i++) {
build(i);
ans += ALGORITHM_MINCOSTFLOW_MinCostFlow(, * n + );
}
return ans;
}
int main() {
int i, j, u, v, c, t;
scanf("%d", &t);
while (t--) {
ALGORITHM_MINCOSTFLOW_clear();
scanf("%d%d", &n, &m);
scanf("%lf%lf", &p[].x, &p[].y);
for (i = ; i <= n; i++) {
scanf("%lf%lf%d%d", &p[i].x, &p[i].y, &sta[i], &en[i]);
for (j = ; j <= m; j++) {
scanf("%d", &ty[i][j]);
}
}
for (i = ; i <= n; i++) {
for (j = i + ; j <= n; j++) {
d[i][j] = d[j][i] = DIS(p[i], p[j]);
}
}
printf("%d\n", solve());
}
return ;
}

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. jq点击和鼠标移上效果以及一个等号"=" 二个等号"==" 三个等号"===" 的区别

    <body> <div class="a" bs='1' style="width:100px; height:30px; border:1px sol ...

  2. 很少有人会告诉你的Android开发基本常识

    原文:很少有人会告诉你的Android开发基本常识. 文章介绍了一些关于开发.测试.版本管理.工具使用等方面的知识.

  3. CLR via C#(10)-参数

    一. 命名参数.可选参数 命名参数和可选参数是在Visual C#2010中引入的新特性. 笨地儿我个瓜不兮兮的,今天才知道. 可选参数:定义方法时为参数设置默认值,调用该方法时可以省略为某些形参指定 ...

  4. 使用HttpWebRequest发送自定义POST请求

    平时用浏览器看网页的时候,点击一下submit按钮的时候其实就是给服务器发送了一个POST请求.但是如何在自己的C#程序里面实现类似的功能呢?本文给出了一个简单的范例,可以实现类似的和web serv ...

  5. jquery.query.js 插件(示例及简单应用)

    帮助文档 var url = location.search; > "?action=view&section=info&id=123&debug&te ...

  6. jQuery - 2.jQuery选择器

    1.id 选择器 2.标签选择器 3.类选择器 4.复合选择器 5.层次选择器 JQuery的迭代   JQuery选择器 JQuery选择器用于查找满足条件的元素,比如可以用$("#控件I ...

  7. MS SQL数据批量备份还原(适用于MS SQL 2005+) 分类: SQL Server 数据库 2015-03-10 14:32 103人阅读 评论(0) 收藏

    我们知道通过Sql代理,可以实现数据库的定时备份功能:当数据库里的数据库很多时,备份一个数据库需要建立对应的定时作业,相对来说比较麻烦: 还好,微软自带的osql工具,比较实用,通过在命令行里里输入命 ...

  8. linux c学习笔记----互斥锁属性

    转自:http://lobert.iteye.com/blog/1762844 互斥锁属性 使用互斥锁(互斥)可以使线程按顺序执行.通常,互斥锁通过确保一次只有一个线程执行代码的临界段来同步多个线程. ...

  9. Android SDK Manager 中如果没有相应的镜像ARM XX Image

    Android SDK Manager 中如果没有相应的镜像ARM XX Image 处理做法是:先更新 相应版本Android SDK Tools 然后出现 ARM XX Image

  10. 如何解决""No boot device available(无可用的引导设备)”错误

    首先换一个镜像文件试一试,如果还不行就按以下方法尝试 http://www.parallelsdesktop.cn/xnjxt-wydsb.html Parallels Desktop 常见问题 ht ...