UVa 469 - Wetlands of Florida
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
// Accepted
// Algorithm: DFS
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 1001;
char adj[101][101] , matrix[101][101] , str[high];
int R, C , area = 0;
void DFS(int x , int y)
{
if(x < 0 || x >= R || y < 0 || y >= C) return;
if(adj[x][y] != 'W') return;
if(adj[x][y] == 'W') adj[x][y] = 'L';
area++;
DFS(x+1, y);
DFS(x-1, y);
DFS(x, y+1);
DFS(x, y-1);
DFS(x+1, y+1);
DFS(x+1, y-1);
DFS(x-1, y+1);
DFS(x-1, y-1);
}
int main()
{
//freopen("out.txt" , "w" , stdout);
int test , tc , i , j , x , y;
sf("%d", &test);
getchar();
getchar();
for(tc=0; tc<test; tc++)
{
R = C = 0;
if(tc) pf("\n");
while(gets(str) && strlen(str) > 0)
{
if(str[0] == 'L' || str[0] == 'W')
{
strcpy(matrix[R] , str);
C = strlen(str);
R++;
}
else
{
sscanf(str , "%d %d", &x , &y);
area = 0;
//cout << x << " " << y << "\n";
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
//cout << adj[i][j] << "; ";
adj[i][j] = matrix[i][j];
}
//cout << "\n";
}
DFS(x-1, y-1);
pf("%d\n" , area);
}
}
}
return 0;
}
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.
*/
// Accepted
// Algorithm: DFS
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
const int mod = 1000007;
const int high = 1001;
char adj[101][101] , matrix[101][101] , str[high];
int R, C , area = 0;
void DFS(int x , int y)
{
if(x < 0 || x >= R || y < 0 || y >= C) return;
if(adj[x][y] != 'W') return;
if(adj[x][y] == 'W') adj[x][y] = 'L';
area++;
DFS(x+1, y);
DFS(x-1, y);
DFS(x, y+1);
DFS(x, y-1);
DFS(x+1, y+1);
DFS(x+1, y-1);
DFS(x-1, y+1);
DFS(x-1, y-1);
}
int main()
{
//freopen("out.txt" , "w" , stdout);
int test , tc , i , j , x , y;
sf("%d", &test);
getchar();
getchar();
for(tc=0; tc<test; tc++)
{
R = C = 0;
if(tc) pf("\n");
while(gets(str) && strlen(str) > 0)
{
if(str[0] == 'L' || str[0] == 'W')
{
strcpy(matrix[R] , str);
C = strlen(str);
R++;
}
else
{
sscanf(str , "%d %d", &x , &y);
area = 0;
//cout << x << " " << y << "\n";
for(i=0; i<R; i++)
{
for(j=0; j<C; j++)
{
//cout << adj[i][j] << "; ";
adj[i][j] = matrix[i][j];
}
//cout << "\n";
}
DFS(x-1, y-1);
pf("%d\n" , area);
}
}
}
return 0;
}
Comments
Post a Comment