HihoCoder - 1478(水陆距离)

#include<stdio.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>

using namespace std;

typedef unsigned long long ULL;

struct node
{
    int x;
    int y;
};

char c[801][801];
int n,m;
int dis[801][801];
int book[801][801];
int nx[4][2]={0,1,
            0,-1,
            -1,0,
            1,0};
queue<node> q;
node next,a;
void bfs()
{
    while(!q.empty())
    {
        a=q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            next.x=a.x+nx[i][0];
            next.y=a.y+nx[i][1];
            if(next.x>=0&&next.y>=0&&next.x<n&&next.y<m&&dis[next.x][next.y]==-1)
            {
                q.push(next);
                dis[next.x][next.y]=dis[a.x][a.y]+1;
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>c[i];
    node t;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            if(c[i][j]=='0')
            {
                dis[i][j]=0;
                t.x=i;
                t.y=j;
                q.push(t);
            }

            else
                dis[i][j]=-1;
    bfs();
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
            cout<<dis[i][j]<<" ";
        cout<<endl;
    }


    return 0;
}
在MATLAB中实现水陆分离通常涉及到图像处理和地理信息系统(GIS)技术。水陆分离的主要目的是从卫星遥感图像或地形数据中识别出水域和陆地部分。以下是一个简单的步骤指南: 1. **读取数据**:首先,你需要导入含有土地和水面信息的遥感图像数据,例如GeoTIFF格式。可以使用`imread`函数读取图像。 ```matlab image = imread('remote_sensing_image.tif'); ``` 2. **预处理**:对图像进行预处理,包括去噪、平滑(如高斯滤波)、归一化等,以便后续分析。 ```matlab image = imfilter(image, fspecial('gaussian', [5 5], 1)); % 高斯滤波 image = mat2gray(image); % 归一化到0-1范围 ``` 3. **水体检测**:使用像SRTM( Shuttle Radar Topography Mission)这样的高分辨率数字高程模型(DEM)结合遥感图像,可以利用灰度值差异来区分水域。比如,可以设置一个阈值,将低于该阈值的部分视为水域。 ```matlab water_threshold = 0.1; % 示例阈值 binary_image = image < water_threshold; ``` 4. **形态学操作**:为了进一步细化结果并去除噪声,可以应用形态学操作,如膨胀(扩大水域区域)和腐蚀(减小非水域区域)。 ```matlab selem = strel('disk', 5); % 创建一个5像素直径的结构元素 binary_image = bwmorph(binary_image, 'open', selem); ``` 5. **水陆分离**:最后,结合DEM的海拔信息,如果某个像素在DEM中的高度接近于零,则标记为水域;反之,标记为陆地。 ```matlab land_sea = logical_or(binary_image, ~dem <= water_threshold); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值