第二周上二分图(Oil Skimming HDU - 4185)

浮油采集算法
本文介绍了一种通过构建二分图并使用匹配算法来解决最大浮油采集次数的问题。该问题设定为在一个N×N的网格中,部分单元格被浮油覆盖,目标是计算能够连续采集两次浮油的最大次数。

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"stdio.h"
#include"string.h"
#include"algorithm"
using namespace std;
char map[1010][1010];
int e[1010][1010],mapp[2500][2500],book1[1010],book2[1010];
int cnt,n,to[4][2]={0,1,0,-1,1,0,-1,0};
bool dfs(int x)
{
	int i;
	for(i=0;i<cnt;i++)
	{
		if(mapp[x][i]&&!book2[i])
		{
			book2[i]=1;
			if(book1[i]==-1||dfs(book1[i]))//如果这个油田还没被选或者之前选这个油田的油田可以找到另一个油田相连
			{
				book1[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int find()
{
	int i,sum=0;
	memset(book1,-1,sizeof(book1));
	for(i=0;i<cnt;i++)
	{
		memset(book2,0,sizeof(book2));
		if(dfs(i))//如果找到了
		sum++;
	}
	return sum;
}
int main()
{
	int t,h=1;
	scanf("%d",&t);
	while(t--)
	{
		memset(mapp,0,sizeof(mapp));
		memset(e,-1,sizeof(e));
		scanf("%d",&n);
		int i,j,k;
		cnt=0;
		for(i=0;i<n;i++)
		scanf("%s",map[i]);
		for(i=0;i<n;i++)//对每个油田进行编号
		{
			for(j=0;j<n;j++)
			{
				if(map[i][j]=='#')
				e[i][j]=cnt++;
			}
		}
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				if(map[i][j]=='#')//找到第一个油田之后找他四周的点
				{
					for(k=0;k<4;k++)
					{
						int tx=i+to[k][0];
						int ty=j+to[k][1];
						if(map[tx][ty]=='#')//有相连的油田,建立连接
						mapp[e[i][j]][e[tx][ty]]=1;
					}
				}
			}
		}
		int s=find();//进行二分查找
		printf("Case %d: %d\n",h++,s/2);//由于有重复的情况,所以结果除以2
	}
	return 0;
}
【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值