Oil Deposits

The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.
Input
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.
Output
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5 
****@
*@@*@
*@**@
@@@*@
@@**@
0 0 
Sample Output

0

1

2

2


典型的bfs,讲课时的案例
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

int dx[8]= {-1,-1,-1,0,0,1,1,1};
int dy[8]= {-1,0,1,-1,1,-1,0,1};

typedef pair<int,int> pot;
int mp[105][105]= {0};
bool vis[105][105]= {0};
int r=0,c=0;
queue<pot> q;

void bfs(int y,int x)
{
    while(!q.empty())q.pop();
    if(vis[y][x])return;
    vis[y][x]=1;

    if(mp[y][x])q.push(pot(y,x));
    while(!q.empty())
    {
        int ty=q.front().first;
        int tx=q.front().second;
        q.pop();
        for(int i=0; i<8; ++i)
        {
            if(vis[ty+dy[i]][tx+dx[i]])continue;
            vis[ty+dy[i]][tx+dx[i]]=1;
            if(mp[ty+dy[i]][tx+dx[i]])q.push(pot(ty+dy[i],tx+dx[i]));
        }
    }
}

int main()
{
    char ip[105];
    while(cin>>r>>c&&r!=0&&c!=0)
    {
        memset(mp,0,sizeof(mp));
        memset(vis,0,sizeof(vis));
        for(int i=0; i<r; ++i)
        {
            cin>>ip;
            for(int j=0; j<c; ++j)
            {
                if(ip[j]=='*')mp[i+1][j+1]=0;
                else if(ip[j]=='@')mp[i+1][j+1]=1;
            }
        }
        int ans=0;
         for(int i=0; i<r; ++i)
        {
            for(int j=0; j<c; ++j){
                if(!vis[i+1][j+1]&&mp[i+1][j+1]){
                    ans++;
                    bfs(i+1,j+1);
                }
                vis[i+1][j+1]=1;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在C#开发中,Windows Media Player控件是集成音频和视频播放功能的强大工具。本文将介绍如何在C#中实现不同的播放模式,如随机播放、列表循环和单曲循环,这些功能在多媒体应用中十分常见 。 要使用Windows Media Player控件,首先需要将其添加到C#项目中。在Visual Studio中,可以通过在工具箱中搜索“Windows Media Player”,并将其拖放到窗体上完成 。接着,设置控件的基本属性,如URL,以指定要播放的媒体文件 。 随机播放模式会在一首歌曲播放结束后,随机选择播放列表中的下一首歌曲。可以通过创建一个包含所有歌曲URL的数组,并利用Random类生成随机索引来实现。例如: 列表循环模式会在一首歌曲播放结束后,自动从播放列表的开头重新开始播放。实现方法是检测到播放结束后,将URL重置为列表的第一个元素: 单曲循环模式则是在一首歌曲播放结束后,重新播放当前歌曲。可以通过将播放器的当前播放位置重置为0并重新播放来实现: 以上代码均需在windowsMediaPlayer1_PlayStateChange事件处理器中实现,该事件会在播放器的播放状态改变时触发 。需要注意的是,这些示例假设已正确引用了WMPLib命名空间,并且Windows Media Player控件的ID为“windowsMediaPlayer” 。 在实际应用中,除了实现播放模式外,还可能需要考虑错误处理、用户界面更新等因素。为了使播放列表更具动态性,可以考虑从数据库或XML文件加载歌曲信息,而不是硬编码在代码中,从而提升用户体验 。通过这些方法,可以在C#中灵活实现Windows Media Player的各种播放模式,满足不同多媒体应用场景的需求 。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值