POJ 3020 Antenna Placement
来源:互联网 发布:spark sql使用 编辑:程序博客网 时间:2024/05/22 01:38
这道题是求最少要建设多少个发射台、、显然的二分匹配啊,但是建立的是无向图所以会多出来一倍的覆盖点啊,实际上有的点是重复了啊,所以需要输出总数-记录的匹配点的一半啊、、
Antenna Placement
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5576 Accepted: 2793
Description
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them.
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?
Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?
Input
On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 <= h <= 40 and 0 < w <= 10. Thereafter is a matrix presented, describing the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space.
Output
For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.
Sample Input
27 9ooo**oooo**oo*ooo*o*oo**o**ooooooooo*******ooo*o*oo*oo*******oo10 1***o******
Sample Output
175
#include <stdio.h>#include <string.h>#include <iostream>using namespace std;int sum, link[500], k;int map[500][500], v[500], dp[500][500];int dfs(int x){ for(int y = 1; y <= k; y++) { if(map[x][y] && !v[y]) { v[y] = 1; if(link[y] == 0 || dfs(link[y])) { link[y] = x; return 1; } } } return 0;}void hungray(){ for(int i = 1; i <= k; i++) { memset(v , 0 , sizeof(v)); if(dfs(i)) sum++; }}int main(){ char s[50][50]; int t, n, m, i, j; scanf("%d",&t); while(t--) { k = 0; memset(map , 0 , sizeof(map)); memset(dp , -1 , sizeof(dp)); memset(link , 0 , sizeof(link)); scanf("%d %d",&n, &m); for(i = 1; i <= n; i++) scanf("%s",s[i]); for(i = 1; i <= n; i++) for(j = 0; j < m; j++) { if(s[i][j] == 'o') dp[i][j+1] = 0; else if(s[i][j] == '*') dp[i][j+1] = ++k; } for(i = 1; i <= n; i++) { for(j = 1; j <= m; j++) { if(dp[i][j] > 0) { if(dp[i-1][j] > 0) map[dp[i][j]][dp[i-1][j]] = 1; if(dp[i+1][j] > 0) map[dp[i][j]][dp[i+1][j]] = 1; if(dp[i][j-1] > 0) map[dp[i][j]][dp[i][j-1]] = 1; if(dp[i][j+1] > 0) map[dp[i][j]][dp[i][j+1]] = 1; } } } sum = 0; hungray(); printf("%d\n",k-sum/2); } return 0;}
- poj 3020 Antenna Placement
- Poj 3020 Antenna Placement
- Poj 3020 Antenna Placement
- poj 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020 Antenna Placement
- poj 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020 Antenna Placement
- POJ 3020Antenna Placement
- 【POJ 3020】Antenna Placement
- poj 3020 Antenna Placement
- poj-3020 Antenna Placement
- POJ 3020 Antenna Placement
- 匿名过程
- JAVA深复制(深克隆)与浅复制(浅克隆)
- Javascript中JQuery选择器
- BAT批处理解决ARP攻击
- python入门的 helloworld
- POJ 3020 Antenna Placement
- RC滤波器
- arduino 通过TTL下载程序
- Flash Builder 找不到所需的Adobe flash player调试器版本
- inode
- 云中的网络:Open vSwitch带来的巨变
- Learning Lua Programming (1) Lua脚本语法说明(修订)
- 【7gyy】轻松四步解决量产U盘问题
- bootstrap modal弹出框