# include <bits/stdc++.h>
using namespace std;
int m[102][102];
struct Fill{
int x,y,t;
};
int main(){
int way[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int L,W,t,x,y,i = 0;
vector<Fill> v;
cin>>L>>W>>t;
// boundary
for(x = 0 ; x<=L+1 ; x++)
m[x][0] = m[x][W+1] = 1;
for(x = 0 ; x<=W+1 ; x++)
m[0][x] = m[L+1][x] = 1;
// input
for(x = 1 ; x<=L ; x++){
for(y = 1 ; y<=W ; y++){
cin>>m[x][y];
if(m[x][y] == 2)
v.push_back({x,y,0});
}
}
// BFS
while(i<v.size()){
for(x = 0 ; x<4 ; x++){
if(v[i].t < t && !m[v[i].x+way[x][0]][v[i].y+way[x][1]]){
v.push_back({v[i].x+way[x][0], v[i].y+way[x][1], v[i].t+1});
m[v[i].x+way[x][0]][v[i].y+way[x][1]] = v[i].t+1;
}
}
i++;
}
cout<<v.size();
}
C. 完美平方數 #include <iostream> #include <math.h> using namespace std; int numSquares(int n); int main() { int num, ans;
Jan 27, 2022E. 鐵路 本題源自於Onling Judge:514 - Rails 題目目標在於給定出站順序的前提下,利用已知入站順序1~N, 確定是否仍能夠以目標出站順序離開。 有一個簡單的想法,我們利用queue的特性來維護出站順序、 利用stack的特性來維護入站順序, 並依次比較它們的front/top是否相同,如果相同就安排出站(pop)。
Jan 27, 2022C. 組合 #include<bits/stdc++.h> using namespace std; vector<int> a; bool first=true,f=true; fstream input,output; void find(int g,vector<int> &can,int p){ if(!g){ if(!first){
Sep 19, 2021B. 嚴格二元樹 # include <iostream> using namespace std; struct Node{ int val, depth; Node *left, *right; Node(int v, int h){ val = v, depth = h;
Sep 16, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up