搜尋 luoguP1162 填塗顏色

2021-08-10 01:53:32 字數 808 閱讀 5539

題目

一道很裸的搜尋題 我們可以一開始把所有的零賦值成2 然後從四條邊界往裡搜 所有與邊界相鄰的2(能搜到的2)都賦值成0即可 最後輸出整個矩陣

**如下

#include

#include

#include

using

namespace

std;

#define in = read();

typedef

long

long ll;

typedef

unsigned

int ui;

const ll size = 50 + 1;

int n;

int num;

intmap[size][size];

bool judge[size][size];

int h[5] = , s[5] = ;

inline ll read()

while(isdigit(ch))

return num*f;

}void dfs(int x , int y)

}int main()

for(register

int i=1;i<=n;i++)

if(map[i][n] == 2)

if(map[1][i] == 2)

if(map[n][i] == 2)

}for(register

int i=1;i<=n;i++)

return0;}

//coyg

luogu P1162 填塗顏色

由數字0組成的方陣中,有一任意形狀閉合圈,閉合圈由數字1構成,圍圈時只走上下左右4個方向。現要求把閉合圈內的所有空間都填寫成2.例如 6 6的方陣 n 6 塗色前和塗色後的方陣如下 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1...

luoguP1162填塗顏色

題目鏈結 這道題剛開始打的暴力,64分。include include include includeusing namespace std const int n 30 int n,a n n last n int main for int i 0 i n i for int i 0 i n i ...

Luogu P1162 填塗顏色題解

問題分析 分析題目可得此問題為連通塊問題 因此題列舉被包圍的 0 較難 所以可用列舉每乙個不被包圍的 0 設計程式 1 include2 include3 include4 include5 include6 using namespace std 7const int n 30 5 8 intn,...