国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

c++隊(duì)列練習(xí)·圖形面積

2023-08-13 09:20 作者:三無的白象牛蛙湯面  | 我要投稿

題目描述

編程計(jì)算由“*”號(hào)圍成的下列圖形的面積。面積計(jì)算方法是統(tǒng)計(jì)*號(hào)所圍成的閉合曲線 中水平線和垂直線交點(diǎn)的數(shù)目。如下圖所示,在 10*10 的二維數(shù)組中,有“*”圍住了 15 個(gè)點(diǎn),因此面積為 15。
?

輸入

一個(gè)10*10的矩陣其中1表示*號(hào)

輸出

一個(gè)數(shù),求被星號(hào)圍起來的面積

樣例輸入

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0

樣例輸出

15

我的看法:洪水填充法有什么難的?!

代碼:

#include<bits/stdc++.h>
using namespace std;
int screen[105][105];
typedef struct vec
{
????int i,j;
}Ract;
queue<Ract> que;
int di[]={1,0,-1,0};
int dj[]={0,-1,0,1};
void flood(int i,int j)
{
????int d;
????Ract pos{i,j};
????screen[i][j]=1;
????que.push(pos);
????while(!que.empty())
????{
????????pos=que.front();
????????que.pop();
????????for(int d=0;d<4;d++)
????????{
????????????int ti=di[d]+pos.i;
????????????int tj=dj[d]+pos.j;
????????????if(screen[ti][tj]==0&&ti<=10&&tj<=10&&ti>=1&&tj>=1)
????????????{
????????????????screen[ti][tj]=1;
????????????????que.push({ti,tj});
????????????}
????????}
????}
}
int main()
{
????int i,j;
????for(int i=1;i<=10;i++)
????{
????????for(int j=1;j<=10;j++)
????????{
????????????scanf("%d",&screen[i][j]);
????????}
????}
????for(int i=1;i<=10;i++)
????{
????????for(int j=1;j<=10;j++)
????????{
????????????if(i==1||j==1||i==10||j==10)
????????????{
????????????????if(screen[i][j]==0)
????????????????????flood(i,j);
????????????}
????????}
????}
????int cnt=0;
????for(int i=1;i<=10;i++)
????{
????????for(int j=1;j<=10;j++)
????????{
????????????if(screen[i][j]==0)
????????????{
????????????????cnt++;
????????????}
????????}
????}
????printf("%d",cnt);
????return 0;
}



c++隊(duì)列練習(xí)·圖形面積的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
泊头市| 喀喇沁旗| 永济市| 伊通| 锦屏县| 临夏县| 鲁甸县| 荣昌县| 远安县| 普格县| 米易县| 永济市| 宜昌市| 阿合奇县| 九龙城区| 浦江县| 四子王旗| 呼玛县| 安义县| 郧西县| 宜都市| 定远县| 会理县| 阜新市| 乐都县| 大庆市| 嘉义县| 肥乡县| 泗洪县| 胶南市| 琼海市| 岳阳县| 郎溪县| 凤阳县| 南陵县| 仪陇县| 海南省| 辉县市| 专栏| 嘉峪关市| 邵武市|