Skip to content

Commit ac28aa9

Browse files
authored
Create labIAbored.cpp
1 parent 8f31043 commit ac28aa9

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

Free/labIAbored.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <bits/stdc++.h>
2+
#define all(x) x.begin(),x.end()
3+
#define msg(str,str2) cout << str << str2<< endl
4+
using namespace std;
5+
6+
using ll = long long;
7+
using ld = long double;
8+
using uint = unsigned int;
9+
using ull = unsigned long long;
10+
template<typename T>
11+
using pair2 = pair<T, T>;
12+
using pii = pair<int, int>;
13+
using pli = pair<ll, int>;
14+
using pll = pair<ll, ll>;
15+
16+
int UMBRAL_ANALISIS=4;
17+
18+
#define pb push_back
19+
#define mp make_pair
20+
21+
int gcd(int a,int b){
22+
if(a%b==0) return b;
23+
else return gcd(b,a%b);
24+
}
25+
26+
clock_t startTime;
27+
double getCurrentTime() {
28+
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
29+
}
30+
int contLakes;
31+
const int N = 100;
32+
char grid[N][N];
33+
bool isVisited[N][N];
34+
int r,c;
35+
int dx[] = {0,-1,-1,-1,0,1,1,1};
36+
int dy[] = {1,1,0,-1,-1,-1,0,1};
37+
int maxUnits = -100;
38+
int contUnits;
39+
unordered_map<int,int> index_total;
40+
vector<char> secuence;
41+
42+
43+
bool isValidPosition(int x, int y){
44+
return x >= 0 && x < r && y>=0 && y < c;
45+
}
46+
47+
void flodFill(int x, int y){
48+
if(isVisited[x][y]) return;
49+
contUnits++;
50+
secuence.push_back(grid[x][y]);
51+
// temp
52+
// cout << "for " << x << " " << y << endl;
53+
// for(auto t: secuence){
54+
// cout << t;
55+
// }cout << endl;
56+
57+
if((int)secuence.size() == UMBRAL_ANALISIS){
58+
cout << "Alert in " << contLakes +1 << endl;
59+
}
60+
61+
isVisited[x][y] = true;
62+
for(int e = 0 ; e < 8 ;e++){
63+
int new_x = x + dx[e];
64+
int new_y = y + dy[e];
65+
if(isValidPosition(new_x,new_y) && grid[new_x][new_y] != 'T'){
66+
flodFill(new_x,new_y);
67+
}
68+
}
69+
secuence.pop_back();
70+
}
71+
72+
void solve(){
73+
cin>>r>>c;
74+
for(int e = 0;e<r;e++){
75+
for(int j = 0;j<c;j++){
76+
cin>>grid[e][j];
77+
}
78+
}
79+
// for(int e = 0;e<r;e++){
80+
// for(int j = 0;j<c;j++){
81+
// cout << grid[e][j];
82+
// }cout << endl;
83+
// }cout << endl;
84+
85+
contLakes = 0;
86+
87+
for(int e = 0;e<r;e++){
88+
for(int j = 0;j<c;j++){
89+
if(grid[e][j] != 'T' && !isVisited[e][j]){
90+
contUnits = 0;
91+
flodFill(e,j);
92+
contLakes++;
93+
index_total[contLakes]= contUnits;
94+
maxUnits = max(maxUnits,contUnits);
95+
}
96+
}
97+
}
98+
cout << "cant lakes: " << contLakes << endl;
99+
cout << "max Units: " << maxUnits << endl;
100+
cout << "idx-total" << endl;
101+
for(auto &[f,s]: index_total){
102+
cout << f << " " << s << endl;
103+
}
104+
105+
}
106+
int main(){
107+
ios_base::sync_with_stdio(false);
108+
cin.tie(0);
109+
#ifdef DEBUG
110+
freopen("input.txt","r",stdin);
111+
freopen("output.txt","w",stdout);
112+
#endif
113+
solve();
114+
return 0;
115+
}

0 commit comments

Comments
 (0)