博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj-2195 Going Home(费用流)
阅读量:5239 次
发布时间:2019-06-14

本文共 2716 字,大约阅读时间需要 9 分钟。

Going Home
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 24304
Accepted: 12198

Description

On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step he moves, until he enters a house. The task is complicated with the restriction that each house can accommodate only one little man. 
Your task is to compute the minimum amount of money you need to pay in order to send these n little men into those n different houses. The input is a map of the scenario, a '.' means an empty space, an 'H' represents a house on that point, and am 'm' indicates there is a little man on that point. 
You can think of each point on the grid map as a quite large square, so it can hold n little men at the same time; also, it is okay if a little man steps on a grid with a house without entering that house.

Input

There are one or more test cases in the input. Each case starts with a line giving two integers N and M, where N is the number of rows of the map, and M is the number of columns. The rest of the input will be N lines describing the map. You may assume both N and M are between 2 and 100, inclusive. There will be the same number of 'H's and 'm's on the map; and there will be at most 100 houses. Input will terminate with 0 0 for N and M.

Output

For each test case, output one line with the single integer, which is the minimum amount, in dollars, you need to pay.

Sample Input

2 2.mH.5 5HH..m...............mm..H7 8...H.......H.......H....mmmHmmmm...H.......H.......H....0 0

Sample Output

21028
题意是,一个人只能到一个房子里面,求最小费用最大流
#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f#define ll long long#define maxn 10010#define maxm 400100using namespace std;struct Edge{ Edge(){}; Edge(int a,int b,int c,int d){v=a;f=b;w=c;nxt=d;}; int v,f,w,nxt;};struct space{ int x,y;}home[maxn],man[maxn];int n,lmt;int g[maxn+10];char mmp[maxn][maxn];Edge e[maxm+10];int nume;int src,sink;void addedge(int u,int v,int c,int w){ e[++nume]=Edge(v,c,w,g[u]); g[u]=nume; e[++nume]=Edge(u,0,-w,g[v]); g[v]=nume;}queue
que;bool inQue[maxn+10];int dist[maxn+10];int prev[maxn+10],pree[maxn+10];bool findpath(){ while(!que.empty())que.pop(); que.push(src);memset(dist,inf,sizeof(dist)); dist[src]=0;inQue[src]=true; while(!que.empty()){ int u=que.front(); que.pop(); for(int i=g[u];i;i=e[i].nxt){ if(e[i].f>0&&dist[u]+e[i].w
>mmp[i];}int l=0,k=0; for(int i=0;i

转载于:https://www.cnblogs.com/da-mei/p/9053262.html

你可能感兴趣的文章
http://overapi.com/
查看>>
游戏生命周期和新服的关系
查看>>
gitlab与gitlab服务器之间的代码迁移
查看>>
NEU校园网登录器
查看>>
如何使用微信小程序video组件播放视频
查看>>
angular清除select空格
查看>>
实验10 指针进阶 程序四
查看>>
java笔记--超级类Object多线程的应用+哲学家进餐算法内部类与多线程结合
查看>>
java笔记--反射进阶之总结与详解
查看>>
(网络数据交互)Android解析Internet的Json资源文件
查看>>
抽象类于接口
查看>>
python学习 day6 (3月7日)
查看>>
BZOJ3270 博物館 概率DP 高斯消元
查看>>
Javascript的加载
查看>>
TCP/IP、Http、Socket的区别
查看>>
vue 封装分页组件
查看>>
深入理解C语言-指针使用的常见错误
查看>>
解决问题1:可以从桌面显示到FORM MFC/HALCON混合编程系列一_打开图像_简单处理_...
查看>>
MEX程序中的mexFunction函数【转】
查看>>
排队理论之性能分析 - Little Law & Utilization Law
查看>>