poj 3686
| Time Limit: 5000MS | Memory Limit: 65536K | |
| Total Submissions: 3791 | Accepted: 1631 |
Description
The Windy's is a world famous toy factory that owns M top-class workshop to make toys. This year the manager receives N orders for toys. The manager knows that every order will take different amount of hours in different workshops. More precisely, the i-th order will take Zij hours if the toys are making in the j-th workshop. Moreover, each order's work must be wholly completed in the same workshop. And a workshop can not switch to another order until it has finished the previous one. The switch does not cost any time.
The manager wants to minimize the average of the finishing time of the N orders. Can you help him?
Input
The first line of input is the number of test case. The first line of each test case contains two integers, N and M (1 ≤ N,M ≤ 50).
The next N lines each contain M integers, describing the matrix Zij (1 ≤ Zij ≤ 100,000) There is a blank line before each test case.
Output
For each test case output the answer on a single line. The result should be rounded to six decimal places.
Sample Input
3 3 4
100 100 100 1
99 99 99 1
98 98 98 1 3 4
1 100 100 100
99 1 99 99
98 98 1 98 3 4
1 100 100 100
1 99 99 99
98 1 98 98
Sample Output
2.000000
1.000000
1.333333
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector> using namespace std; const int MAX = ;
const int INF = 1e9 + ;
int N, M;
int z[MAX][MAX];
struct Edge {int from, to, cap, flow, cost;};
vector<Edge> edges;
vector<int> G[MAX * MAX * MAX + * MAX];
int p[MAX * MAX * MAX + * MAX], a[MAX * MAX * MAX + * MAX];
int d[MAX * MAX * MAX + * MAX];
bool inq[MAX * MAX * MAX + * MAX]; void add_edge(int from, int to, int cap, int cost) {
edges.push_back(Edge {from, to, cap, , cost});
edges.push_back(Edge {to, from, , , -cost});
int m = edges.size();
G[from].push_back(m - );
G[to].push_back(m - );
} bool bellmanford(int s, int t, int &flow, int &cost) {
for(int i = s; i <= t; ++i) {
d[i] = INF;
} memset(inq, , sizeof(inq));
d[s] = ; inq[s] = ; p[s] = ; a[s] = INF; queue<int> Q;
Q.push(s);
while(!Q.empty()) {
//printf("fuck\n");
int u = Q.front(); Q.pop();
inq[u] = ;
for(int i = ; i < G[u].size(); ++i) {
Edge& e = edges[ G[u][i] ];
if(e.cap > e.flow && d[e.to] > d[u] + e.cost) {
d[e.to] = d[u] + e.cost;
p[e.to] = G[u][i];
a[e.to] = min(a[u], e.cap - e.flow);
if(!inq[e.to]) {
inq[e.to] = ;
Q.push(e.to);
}
}
}
} if(d[t] == INF) return ;
flow += a[t];
cost += d[t] * a[t]; int u = t;
while(u != s) {
edges[p[u]].flow += a[t];
edges[p[u] ^ ].flow -= a[t];
u = edges[p[u]].from;
} return ;
} int Mincost(int s, int t) {
int flow = , cost = ;
while(bellmanford(s, t, flow, cost));
return cost;
} int main()
{
//freopen("sw.in", "r", stdin);
int t;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &N, &M);
for(int i = ; i <= N; ++i) {
for(int j = ; j <= M; ++j) {
scanf("%d", &z[i][j]);
//printf("%d ", z[i][j]);
}
} int s = , t = N + N * M + ;
for(int i = s; i <= t; ++i) G[i].clear();
edges.clear(); for(int i = ; i <= N; ++i) {
add_edge(s, i, , );
} for(int j = ; j <= M; ++j) {
for(int k = ; k <= N; ++k) {
add_edge(j * N + k, t, , );
for(int i = ; i <= N; ++i) {
add_edge(i, j * N + k, , z[i][j] * k);
}
}
}
printf("%.6f\n", (double) Mincost(s, t) / N); } //cout << "Hello world!" << endl;
return ;
}
poj 3686的更多相关文章
- POJ 3686 The Windy's(思维+费用流好题)
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5362 Accepted: 2249 Descr ...
- poj 3686 The Windy's
http://poj.org/problem?id=3686 #include <cstdio> #include <cstring> #include <algorit ...
- poj 3686(拆点+最小权匹配)
题目链接:http://poj.org/problem?id=3686 思路:显然工件为X集,机器为Y集合.由于每个机器一次只能加工一个部件,因此我们可以将一台机器拆成N个点,至于部件与机器之间连多大 ...
- POJ 3686 The Windy's (费用流)
[题目链接] http://poj.org/problem?id=3686 [题目大意] 每个工厂对于每种玩具的加工时间都是不同的, 并且在加工完一种玩具之后才能加工另一种,现在求加工完每种玩具的平均 ...
- POJ 3686:The Windy's(最小费用最大流)***
http://poj.org/problem?id=3686 题意:给出n个玩具和m个工厂,每个工厂加工每个玩具有一个时间,问要加工完这n个玩具最少需要等待的平均时间.例如加工1号玩具时间为t1,加工 ...
- Poj(3686),最小权匹配,多重匹配,KM
题目链接 The Windy's | Time Limit: 5000MS | Memory Limit: 65536K | | Total Submissions: 4939 | Accepted: ...
- [ACM] POJ 3686 The Windy's (二分图最小权匹配,KM算法,特殊建图)
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4158 Accepted: 1777 Descr ...
- poj 3686 Priest John's Busiest Day
http://poj.org/problem?id=3683 2-sat 问题判定,输出一组可行解 http://www.cnblogs.com/TheRoadToTheGold/p/8436948. ...
- POJ 3686 The Windy's 最小费用最大流
每个工厂拆成N个工厂,费用分别为1~N倍原费用. //#pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...
随机推荐
- 在mac系统安装Apache Tomcat的详细步骤[转]
对于Apache Tomcat 估计很多童鞋都会,那么今天就简单说下在mac上进行tomcat的安装: 第一步:下载Tomcat 这里Himi下载的tomcat version:7.0.27 直接 ...
- Mysql账号管理
一 用户添加 通过insert 方式添加用户 insert into mysql.user(Host,User,Password) values("localhost"," ...
- arcgis中求多点到一条曲线的最短欧几里得距离
1.使用的工具:Arctoolbox----Analysis Tools----Proximity----Near工具. 2.注意:在求距离之前一定要先设置好坐标系统.
- linux中fork()函数详解
一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同, ...
- eclipse java.lang.OutOfMemoryError: Java heap space
1.手动编译运行需要添加 java -Xms256m -Xmx1024m classname 2.在eclipse中,在run as -> run configurations -> ar ...
- Windows Phone8.1 SDK中的新控件
前言 WP8.1对开发者的影响要远大于对用户的影响.这篇博客就来一起看看哪些WP8.0中的控件被移除或替换,这些控件的介绍在MSDN上都非常的详细,所以这里只给出一些简单的介绍,来对比8.1 ...
- shell 函数
1 shell函数的定义及其调用 shell函数有两种格式: function name { commands } name() { commands } 其中,name为函数名,commands为函 ...
- Django ajax MYSQL Highcharts<1>
Another small project with django/Ajax/Mysql/Highcharts. 看下效果图 - delivery dashboard .嘿嘿 是不是还蛮好看的. 废 ...
- 可综合风格的VerilogHDL模块实例
1.赋值语句:assign{cout,sum}=a+b+cin; 2.利用电平敏感的always块设计组合逻辑电路 3.always块中如果含有局部变量,就必须在begin后加模块名,是必须加,同样的 ...
- NSNumber、NSValue、NSDate、NSObject
注:OC中数组和字典只能存储OC对象不能存放基本数据类型. NSNumber NSNumber可以用来把一个基本数据类型包装成一个NSNumber类型的对象. NSNumber *number = [ ...