博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1533 Going home
阅读量:4486 次
发布时间:2019-06-08

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

Going Home

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2829    Accepted Submission(s): 1423

Problem 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
.m
H.
 
5 5
HH..m
.....
.....
.....
mm..H
 
7 8
...H....
...H....
...H....
mmmHmmmm
...H....
...H....
...H....
 
0 0
 

 

Sample Output
2
10
28
 
#include 
#include
#include
#include
#define N 110#define INF 99999999int n, m;char map[N][N]; //存储原始字符地图的int ma[N][N]; //类似边表的可匹配存储int lx[N], ly[N];int vtx[N], vty[N];int match[N];int slack[N];int cnt;int max(int a, int b){ return a>b?a:b;}int min(int a, int b){ return a>b?b:a;}int hungary(int dd) //匈牙利算法{ int i; vtx[dd]=1; for(i=0; i

 

 
#include
#include
#include
#include
#include
#define N 110using namespace std;char maps[N][N]; //存储原始字符地图的int map[N][N]; //类似边表的可匹配存储int lx[N], ly[N];int slack[N];int match[N];bool visitx[N], visity[N];int n;bool Hungary( int u ) //匹配{ int i ; visitx[u] = true; for( i=0; i < n; ++i) { if(visity[i]==true ) continue; else { if(lx[u] + ly[i] == map[u][i] ) { visity[i] = true; if(match[i] == -1 || Hungary(match[i]) ) { match[i] = u; return true; } } else slack[i] = min(slack[i], lx[u] + ly[i]-map[u][i] ); } } return false;}void KM_perfect_match() //匈牙利算法{ int temp; memset(lx, 0, sizeof(lx)); // 清零?? memset(ly, 0, sizeof(ly)); // 清零?? for(int i=0; i

 

转载于:https://www.cnblogs.com/yspworld/p/3926311.html

你可能感兴趣的文章
MySQL常用存储引擎:MyISAM与InnoDB之华山论剑
查看>>
MVC5+EF6 --自定义控制Action访问权限
查看>>
[CF786B] Legacy
查看>>
Spring 注解@Component,@Service,@Controller,@Repository
查看>>
设置RDLC中table控件的表头在每页显示
查看>>
linux中tomcat内存溢出解决办法 分类: 测试 ...
查看>>
jQuery $.each用法
查看>>
[Luogu 3902]Increasing
查看>>
clear语句处理不同类型的数据结果
查看>>
HDU 6118 度度熊的交易计划(费用流)
查看>>
UrlEncode编码/UrlDecode解码使用方法
查看>>
使用ubuntu作为web开发环境的一些感受
查看>>
easyui-datagrid 自适应列宽问题
查看>>
OO第一次总结
查看>>
VS2012发布网站详细步骤
查看>>
文件下载隐匿执行
查看>>
【导图控】各软件开发版本详解
查看>>
HDU 1533 Going home
查看>>
Extjs面板和布局初探
查看>>
箭头函数
查看>>