Thanks to a certain “green” resources company, there is a new profitable industry of oil skimming. There are large slicks of crude oil floating in the Gulf of Mexico just waiting to be scooped up by enterprising oil barons. One such oil baron has a special plane that can skim the surface of the water collecting oil on the water’s surface. However, each scoop covers a 10m by 20m rectangle (going either east/west or north/south). It also requires that the rectangle be completely covered in oil, otherwise the product is contaminated by pure ocean water and thus unprofitable! Given a map of an oil slick, the oil baron would like you to compute the maximum number of scoops that may be extracted. The map is an NxN grid where each cell represents a 10m square of water, and each cell is marked as either being covered in oil or pure water.
Input
The input starts with an integer K (1 <= K <= 100) indicating the number of cases. Each case starts with an integer N (1 <= N <= 600) indicating the size of the square grid. Each of the following N lines contains N characters that represent the cells of a row in the grid. A character of ‘#’ represents an oily cell, and a character of ‘.’ represents a pure water cell.
Output
For each case, one line should be produced, formatted exactly as follows: “Case X: M” where X is the case number (starting from 1) and M is the maximum number of scoops of oil that may be extracted.
Sample Input
1
6
……
.##…
.##…
….#.
….##
……
Sample Output
Case 1: 3
这玩意就是要用邻接表建图..
邻接矩阵邪教我已经嫌弃好几天了
#include <iostream>
#include <cstring>
#include<algorithm>
#include <cstdio>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<stack>
using namespace std;
int cc = 0;
int tu[611][611],use[611*611],vis[611*611];
int n, m,p;
string t[611];
int bj[611][611];
vector<int>tt[611 * 611];
int zhao(int gen)
{
for (int a = 0; a < tt[gen].size(); a++)
{
if (vis[tt[gen][a]])continue;
vis[tt[gen][a]] = 1;
if (use[tt[gen][a]] == 0 || zhao(use[tt[gen][a]]) == 1)
{
use[tt[gen][a]] = gen;
return 1;
}
}
return 0;
}
int xiongyali()
{
int fs = 0;
memset(use, 0, sizeof(use));
for (int a = 1; a <= cc; a++)
{
memset(vis, 0, sizeof(vis));
if (zhao(a))fs++;
}
return fs;
}
map<pair<int,int>, int>mp;
int main()
{
int T;
cin >> T;
int u = 0;
while (T--)
{
mp.clear();
memset(bj, 0, sizeof(bj));
cin >> n;
for (int a = 0; a <= n*n+10; a++)tt[a].clear();
cc = 0;
for (int a = 0; a < n; a++)cin >> t[a];
for (int a = 0; a < n; a++)
{
for (int b = 0; b < n; b++)
{
if (t[a][b] != '#')continue;
bj[a][b] = ++cc;
}
}
for (int a = 0; a < n; a++)
{
for (int b = 0; b < n; b++)
{
if (!bj[a][b])continue;
if (a + 1 < n && bj[a + 1][b])
{
tt[bj[a + 1][b]].push_back(bj[a][b]);
tt[bj[a][b]].push_back(bj[a+1][b]);
}
if (b + 1 < n && bj[a ][b+ 1])
{
tt[bj[a ][b+ 1]].push_back(bj[a][b]);
tt[bj[a][b]].push_back(bj[a ][b+ 1]);
}
}
}
printf("Case %d: %d\n", ++u,xiongyali()/2);
}
}

本文介绍了一种针对海上油污清理的无人机路径规划算法。该算法通过建立邻接表来表示油污区域,利用匹配算法计算出无人机在油污上的最大有效清理次数。适用于大规模海上油污清理作业。
1083

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



