原题链接:http://poj.org/problem?id=2112
| Time Limit: 2000MS | Memory Limit: 30000K | |
| Total Submissions: 11878 | Accepted: 4307 | |
| Case Time Limit: 1000MS | ||
Description
Each milking point can "process" at most M (1 <= M <= 15) cows each day.
Write a program to find an assignment for each cow to some milking machine so that the distance the furthest-walking cow travels is minimized (and, of course, the milking machines are not overutilized). At least one legal assignment is possible for all input data sets. Cows can traverse several paths on the way to their milking machine.
Input
* Lines 2.. ...: Each of these K+C lines of K+C space-separated integers describes the distances between pairs of various entities. The input forms a symmetric matrix. Line 2 tells the distances from milking machine 1 to each of the other entities; line 3 tells the distances from machine 2 to each of the other entities, and so on. Distances of entities directly connected by a path are positive integers no larger than 200. Entities not directly connected by a path have a distance of 0. The distance from an entity to itself (i.e., all numbers on the diagonal) is also given as 0. To keep the input lines of reasonable length, when K+C > 15, a row is broken into successive lines of 15 numbers and a potentially shorter line to finish up a row. Each new row begins on its own line.
Output
Sample Input
2 3 2 0 3 2 1 1 3 0 3 2 0 2 3 0 1 0 1 2 1 0 2 1 0 0 2 0
Sample Output
2
题意:有K台挤奶机(编号1~K),C头奶牛(编号K+1~K+C),都视为点,现在要让C头奶牛到挤奶机去挤奶,每台挤奶机只能处理M头奶牛,求使所走路程最远的奶牛的路程最短的方案。
思路:最大流的变种题,难点在于构图。先用Floyd算法求所有点对之间最短路。然后二分最短长度,若奶牛与挤奶机之间的距离大于mid则不连边,否则将对应奶牛与挤奶机连容量为1的边。源向各个奶牛流连容量为1的边,各个挤奶机向汇点连容量为M的边,然后直接用求最大流的dinic算法的板,看是否满流。
AC代码:
#include "iostream"
#include "queue"
#include "stdio.h"
using namespace std;
#define N 250
#define M 50000
#define INF 1000000000
int k,c,m,nn,max1=0;
int head[N], cur[N], d[N], st[M], s, e, no, n,a[240][240];
struct point{
int u, v, flow, next;
point(){};
point(int x, int y, int z, int w):u(x), v(y), next(z), flow(w){};
}p[M];
void add(int x, int y, int z){
p[no] = point(x, y, head[x], z); head[x] = no++;
p[no] = point(y, x, head[y], 0); head[y] = no++;
}
void init(){
memset(head, -1, sizeof(head));
no = 0;
}
bool bfs(){
int i, x, y;
queueq;
memset(d, -1, sizeof(d));
d[s] = 0; q.push(s);
while(!q.empty()){
x = q.front(); q.pop();
for(i = head[x]; i != -1; i = p[i].next){
if(p[i].flow && d[y = p[i].v] < 0){
d[y] = d[x] + 1;
if(y == e) return true;
q.push(y);
}
}
}
return false;
}
int dinic(){
int i, loc, top, x = s, nowflow, maxflow = 0;
while(bfs()){
for(i = s; i <= e; i++) cur[i] = head[i];
top = 0;
while(true){
if(x == e){
nowflow = INF;
for(i = 0; i < top; i ++){
if(nowflow > p[st[i]].flow){
nowflow = p[st[i]].flow;
loc = i;
}
}
for(i = 0; i < top; i++){
p[st[i]].flow -= nowflow;
p[st[i]^1].flow += nowflow;
}
maxflow += nowflow;
top = loc; x = p[st[top]].u;
}
for(i = cur[x]; i != -1; i = p[i].next)
if(p[i].flow && d[p[i].v] == d[x] + 1) break;
cur[x] = i;
if(i != -1){
st[top ++] = i;
x = p[i].v;
}
else {
if(!top) break;
d[x] = -1;
x = p[st[--top]].u;
}
}
}
return maxflow;
}
void floyd()
{
for(int i=1;i<=nn;i++)
for(int j=1;j<=nn;j++)
for(int w=1;w<=nn;w++)
{
if(a[j][w]>a[j][i]+a[i][w])
a[j][w]=a[j][i]+a[i][w];
}
}
void solve()
{
int left=0,right=max1,mid;
while(left
本文深入探讨了深度学习在人工智能领域的应用,包括卷积神经网络、循环神经网络、自动推理系统等关键技术,并展示了这些技术在自动驾驶、图像处理、自然语言处理等实际场景中的应用案例。
449

被折叠的 条评论
为什么被折叠?



