五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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)遵守國家法律
社旗县| 富锦市| 和硕县| 五台县| 辽宁省| 托里县| 八宿县| 高唐县| 湘西| 横峰县| 临海市| 永康市| 太保市| 海盐县| 雅江县| 河北省| 乌拉特前旗| 清原| 杭锦后旗| 平南县| 永川市| 勐海县| 抚远县| 吴忠市| 平罗县| 新郑市| 子长县| 富蕴县| 静宁县| 黄平县| 黄冈市| 青州市| 华容县| 嘉义县| 错那县| 安福县| 南岸区| 西乌珠穆沁旗| 迁安市| 江孜县| 灵璧县|