Skip to content

Commit 72708cd

Browse files
committed
[uva] Add C++ solution for 469 - Wetlands of Florida.
1 parent 703bb29 commit 72708cd

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

uva/00469-1.ans

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
12
2+
4

uva/00469-1.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1
2+
3+
LLLLLLLLL
4+
LLWWLLWLL
5+
LWWLLLLLL
6+
LWWWLWWLL
7+
LLLWWWLLL
8+
LLLLLLLLL
9+
LLLWWLLWL
10+
LLWLWLLLL
11+
LLLLLLLLL
12+
3 2
13+
7 5

uva/00469.cc

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// https://uva.onlinejudge.org/external/4/469.pdf
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
using vs=vector<string>;
5+
using vi=vector<int>;
6+
using vvi=vector<vi>;
7+
int main(){
8+
ios::sync_with_stdio(0);
9+
cin.tie(0);
10+
int t;
11+
string s;
12+
cin>>t;
13+
getline(cin,s);
14+
getline(cin,s);
15+
for(int T=0;T<t;T++){
16+
if(T)cout<<"\n";
17+
vs a;
18+
for(;;){
19+
getline(cin,s);
20+
if(s.empty())break;
21+
if(s[0]!='L'&&s[0]!='W')break;
22+
a.push_back(s);
23+
}
24+
int n=a.size();
25+
if(!n)continue;
26+
int m=a[0].size();
27+
vvi c(n,vi(m));
28+
function<void(int,int,int)>dfs=[&](int y,int x,int k){
29+
c[y][x]=k;
30+
if(x>0&&!c[y][x-1]&&a[y][x-1]=='W')dfs(y,x-1,k);
31+
if(y>0&&x>0&&!c[y-1][x-1]&&a[y-1][x-1]=='W')dfs(y-1,x-1,k);
32+
if(y>0&&!c[y-1][x]&&a[y-1][x]=='W')dfs(y-1,x,k);
33+
if(y>0&&x<m-1&&!c[y-1][x+1]&&a[y-1][x+1]=='W')dfs(y-1,x+1,k);
34+
if(x<m-1&&!c[y][x+1]&&a[y][x+1]=='W')dfs(y,x+1,k);
35+
if(y<n-1&&x<m-1&&!c[y+1][x+1]&&a[y+1][x+1]=='W')dfs(y+1,x+1,k);
36+
if(y<n-1&&!c[y+1][x]&&a[y+1][x]=='W')dfs(y+1,x,k);
37+
if(y<n-1&&x>0&&!c[y+1][x-1]&&a[y+1][x-1]=='W')dfs(y+1,x-1,k);
38+
};
39+
int k=1;
40+
for(int i=0;i<n;i++)
41+
for(int j=0;j<m;j++)
42+
if(!c[i][j]&&a[i][j]=='W'){
43+
dfs(i,j,k++);
44+
}
45+
vi b(k);
46+
for(int i=0;i<n;i++)
47+
for(int j=0;j<m;j++)
48+
if(c[i][j])
49+
b[c[i][j]]++;
50+
for(;;){
51+
if(s.empty())break;
52+
stringstream in(s);
53+
int y,x;
54+
in>>y>>x;
55+
y--;x--;
56+
cout<<b[c[y][x]]<<endl;
57+
getline(cin,s);
58+
}
59+
}
60+
}

uva/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ There are solutions for the following
2727
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=399))
2828
1. [459 - Graph Connectivity](00459.cc)
2929
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=400))
30+
1. [469 - Wetlands of Florida](00469.cc)
31+
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=410))
3032
1. [483 - Word Scramble](00483.py)
3133
([problem site](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=424))
3234
1. [572 - Oil Fields](00572.cc)

0 commit comments

Comments
 (0)