## 469 - Wetlands of Florida

Moderator: Board moderators

litehiro
New poster
Posts: 1
Joined: Thu Sep 02, 2004 7:04 pm

hi all.. i keep getting WA.. don't know what's wrong..

is there any tricky???? or maybe i'm doing wrong with the input??

anyway here is my code, can someone trace it/show my mistake???

***********

program wetland;
const
max=100;
movb:array[1..8] of longint = (0,-1,0,1,1,1,-1,-1);
movk:array[1..8] of longint = (-1,0,1,0,1,-1,1,-1);
var
temp:string;
cs,totcase,code,pos,posb,posk,tot,i,bar,kol:longint;
a:array[0..max,0..max] of char;
st:array[0..max,0..max] of boolean;

procedure flood(x,y:longint);
var
i:longint;
begin
st[x,y]:=true;
tot:=tot+1;
for i:=1 to 8 do
if (a[x+movb,y+movk]='W') and (st[x+movb,y+movk]=false) then
flood(x+movb,y+movk);
end;

procedure trim;
begin
repeat
if temp in ['1'..'9'] = false then
temp:=copy(temp,2,length(temp)-1);
until temp in ['1'..'9'];
pos:=0;
repeat
pos:=pos+1;
until temp[pos]=' ';
val(copy(temp,1,pos-1),posb,code);
val(copy(temp,pos+1,length(temp)-pos),posk,code);
end;

begin
for cs:=1 to totcase do
begin
if cs>1 then writeln;

fillchar(a,sizeof(a),' ');

temp:='';
repeat
until temp<>'';

kol:=length(temp);
bar:=1;
for i:=1 to kol do
a[bar,i]:=temp;

repeat

temp:='';
repeat
until temp<>'';

if temp in ['L','W'] then
begin
bar:=bar+1;
for i:=1 to kol do
a[bar,i]:=temp;
end;
until temp in ['L','W'] = false;

trim;
tot:=0;
if a[posb,posk]='W' then
flood(posb,posk);
writeln(tot);

fillchar(st,sizeof(st),false);
repeat

if temp<>'' then
begin
trim;
tot:=0;
if (a[posb,posk]='W') and (st[posb,posk]=false) then
flood(posb,posk);
writeln(tot);
end;
until temp='';

end;

end.

******************************

shihabrc
New poster
Posts: 49
Joined: Sun Sep 18, 2005 10:20 am
Location: CSE,BUET
Contact:

### 469 RTE. HELP REQUIRED!!!!

This code is generating RTE. Can't find why. CAn any one help??

Code: Select all

``````#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

int k;
int count;
int row,col;
char tempin;

void initk(void){
k=-1;
k=0;
k=1;
k=0;
k=0;
k=1;
k=0;
k=-1;
k=-1;
k=1;
k=-1;
k=-1;
k=1;
k=1;
k=1;
k=-1;
}

struct input {
char pixel;
int visited;
};

struct input in;

void dfs(int,int);
void visit(int,int);
void init(void);
void initmat(void);

void main(void){
int n,i,p,r,c,m,q;
char t;
scanf("%d", &n);
gets(t);
gets(t);
initk();
for(i=0;i<n;i++){
initmat();
gets(in.pixel);
col=strlen(in.pixel);
p=1;
while(gets(in[p].pixel)!=NULL){
if(in[p].pixel=='\0' || in[p].pixel=='\n') break;
if(isdigit(in[p].pixel)) {
r=atoi(strtok(in[p].pixel," "));
c=atoi(strtok(NULL," "));
break;
}
p++;
}
m=1;
while(gets(tempin)!=NULL){
if(tempin=='\n' || tempin=='\0') break;
r[m]=atoi(strtok(tempin," "));
c[m]=atoi(strtok(NULL, " "));
m++;
}
row=p;
for(q=0;q<m;q++){
count=0;
init();
if(r[q]==0 || c[q]==0) {
count=0;
}
else dfs(r[q]-1,c[q]-1);
printf("%d\n",count);
}
printf("\n");
}
}

void dfs(int i, int j){
if(in[i].pixel[j]=='W') count++;
visit(i,j);
}

void visit(int u,int v){
int p,nr=0,nc=0;
in[u].visited[v]=1;
for(p=0;p<8;p++){
nr=u+k[p];
nc=v+k[p];
if((nr>=0 && nr<row) && (nc>=0 && nc<col) && in[u].pixel[v]=='W' && in[nr].pixel[nc]=='W' && in[nr].visited[nc]==0){
visit(nr,nc);
count++;
}
}

}

void init(void){
int i,j;
for(i=0;i<200;i++){
for(j=0;j<200;j++){
in[i].visited[j]=0;
}
}
}

void initmat(void){
int i,j;
for(i=0;i<200;i++){
for(j=0;j<200;j++){
in[i].pixel[j]='0';
}
}
}
``````

pregunton2
New poster
Posts: 1
Joined: Wed Oct 26, 2005 6:38 pm

### I got RTE... why???

Hi... this is may code... I don

Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:
Hints:
- If the given coordinate contains 'L', just output 0, otherwise count the pieces of water
- Use floodfill with 8 direction
- If the problems give same coordinate that containts 'W', give the correct output also (this make my first program got WA!), be careful!

Here are the input for my AC-ed program:

Code: Select all

``````5

LLLLLLLLL
LLWWLLWLL
LWWLLLLLL
LWWWLWWLL
LLLWWWLLL
LLLLLLLLL
LLLWWLLWL
LLWLWLLLL
LLLLLLLLL
3 2
7 5
3 2
7 5

LLLLLLLLL
LLWWLLWLL
LWWLLLLLL
LWWWLWWLL
LLLWWWLLL
LLLLLLLLL
LLLWWLLWL
LLWLWLLLL
LLLLLLLLL
1 5
2 5
4 5

LLLLLLLLL
LLWWLLWLL
LWWLLLLLL
LWWWLWWLL
LLLWWWLLL
LLLLLLLLL
LLLWWLLWL
LLWLWLLLL
LLLLLLLLL
7 7
8 8
9 9
1 1
2 2

LLLWL
LLWLL
1 1
1 4
2 2
2 6
2 7
3 1

LLWLL
LWLWL
LLWLL
2 3

``````
And here are the output for my AC-ed program:

Code: Select all

``````12
4
12
4

0
0
0

0
0
0
0
0

0
2
0
0
0
0

0
``````
Hope it helps... asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

### 469...why TLE???

so funny thing is i m gettign TLE. before this i submitted two same type of code and get accepted. but now strange TLE in this problem!!!!!! where is my fault?? plz helm

Code: Select all

``````got accepted
``````
help would be appreciated.
Last edited by asif_rahman0 on Mon Apr 24, 2006 7:19 pm, edited 1 time in total.

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Contact:

### Re: 469...why TLE???

asif_rahman0 wrote:so funny thing is i m gettign TLE.
Not so funny Last line of the input may not be an empty line but EOF marker. Handle that properly.

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm
thnx mamun vai:)
really its not "so funny"!!!

bekerpico
New poster
Posts: 2
Joined: Wed Aug 02, 2006 1:08 am
Location: Cairo
Contact:

### Hint ...

hi ,
i submitted my code and i got runtime error and i know that runtime
error got when i get pointer to unreachable area like array[-1] ....
so i increase lands array's size until it reach r and i got
accepted ... i dunna why !! ... cause problem state that "Each input
set consists of lines each containing character long sequence of `
`L''s and ``W''s followed by k > 0 lines each containing" ....

then i know why ... cause k >0 and not specified ....

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

### Why WA??

This is one of the worst problems of this archive. What is it that they are trying to test, our problem solving ability, or our ability to parse the input?
Anyway, I keep getting WA after repeated submissions. Could anyone point out the mistake in the code, or provide me with sample I/O with which I could debug my code?

Code: Select all

``````#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<cctype>
#include<stack>
#include<map>
#include<set>
using namespace std;
int main()
{
int n;
cin>>n;
string temp;
getline(cin,temp,'\n');
getline(cin,temp,'\n');
while(n--)
{
//		cout<<n<<endl;
vector<string> v;
int startx,starty;
int flag1=0;
while(1)
{
string s;
if(!getline(cin,s,'\n'))
exit(0);
if(s=="")
{
flag1=1;
break;
}
int flag=1;
for(int i=0;i<s.size() && flag;i++)
{
if(isdigit(s[i]))
flag=0;
}
if(flag)
{
v.push_back(s);
//	cout<<s<<endl;
}
else
{
sscanf(s.c_str()," %d %d",&startx,&starty);
break;
}
}
if(flag1)
continue;
while(1)
{

startx--,starty--;
if(startx <0 || startx >= v.size() || starty <0 || starty >= v.size() || v[startx][starty]!='W')
{

printf("%d\n",0);
}
else
{
vector<string> tempv=v;
int c=1;
queue<pair<int,int> > q;
q.push(make_pair(startx,starty));
v[startx][starty]='V';
while(!q.empty())
{
pair<int,int> t1=q.front();
q.pop();
int x=t1.first,y=t1.second;
//	cout<<x<<" "<<y<<endl;
if(x >0 && y>0 && v[x-1][y-1]=='W')
{
c++;
v[x-1][y-1]='V';
q.push(make_pair(x-1,y-1));
}
if(x >0  && v[x-1][y]=='W')
{
c++;
v[x-1][y]='V';
q.push(make_pair(x-1,y));
}
if(x >0 && y<v.size() -1 && v[x-1][y+1]=='W')
{
c++;
v[x-1][y+1]='V';
q.push(make_pair(x-1,y+1));
}
if(y>0 && v[x][y-1]=='W')
{
c++;
v[x][y-1]='V';
q.push(make_pair(x,y-1));
}
if(y<v.size() && v[x][y+1]=='W')
{
c++;
v[x][y+1]='V';
q.push(make_pair(x,y+1));
}
if(x <v.size()-1  && y>0 && v[x+1][y-1]=='W')
{
c++;
//		printf("Hello\n");
v[x+1][y-1]='V';
q.push(make_pair(x+1,y-1));
}
if(x<v.size()-1 && v[x+1][y]=='W')
{
c++;
v[x+1][y]='V';
q.push(make_pair(x+1,y));
}
if(x <v.size()-1 && y<v.size()-1 && v[x+1][y+1]=='W')
{
c++;
v[x+1][y+1]='V';
q.push(make_pair(x+1,y+1));
}
}
printf("%d\n",c);
v=tempv;
}
string s;
if(!getline(cin,s,'\n'))
exit(0);
if(s=="")
break;
sscanf(s.c_str()," %d %d",&startx,&starty);
}
if(n)
printf("\n");
}
return 0;
}

``````

Thanks

algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am
I used this form to take the input

Code: Select all

``````int tcas,R,C;
char temp;

scanf("%d\n",&tcas);
while(tcas--)
{
while(1)
{
gets(temp);
if(temp!='W'&&temp!='L') break;
....
....
}
sscanf(temp,"%d %d",&R,&C);
....
while(gets(temp))
{
if(!strlen(temp)) break;
sscanf(temp,"%d %d",&R,&C);
....
....
....
}
}
``````

frandres
New poster
Posts: 2
Joined: Mon Dec 24, 2007 7:34 am
Hey guys...

Need help here.. I've tried all the input examples you've written so far in this topic and I keep getting WA Heres my code

Code: Select all

``````
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector <string> grid;
unsigned int area=0;

{
grid[row][column]='R';

//Up
if ((row-1>=0)&& (grid[row-1][column]=='W' || grid[row-1][column]=='C'))
{
if (grid[row-1][column]=='W')
area++;

grid[row-1][column]='C';

}

//Down
if ((row+1<grid.size())&& (grid[row+1][column]=='W' || grid[row+1][column]=='C'))
{
if (grid[row+1][column]=='W')
area++;

grid[row+1][column]='C';

}

//Left
if ((column-1>=0)&& (grid[row][column-1]=='W' || grid[row][column-1]=='C'))
{

if (grid[row][column-1]=='W')
area++;

grid[row][column-1]='C';

}

//Right
if ((column+1<grid.size())&& (grid[row][column+1]=='W' || grid[row][column+1]=='C'))
{

if (grid[row][column+1]=='W')
area++;

grid[row][column+1]='C';

}

//Upper left
if ((row-1>=0)&& (column-1>=0) && (grid[row-1][column-1]=='W' || grid[row-1][column-1]=='C'))
{

if (grid[row-1][column-1]=='W')
area++;

grid[row-1][column-1]='C';

}

//Upper right
if ((row-1>=0)&& (column+1<grid.size()) && (grid[row-1][column+1]=='W' || grid[row-1][column+1]=='C'))
{

if (grid[row-1][column+1]='W')
area++;

grid[row-1][column+1]='C';

}

//Bottom left
if ((row+1<grid.size()) && (column-1>=0) && (grid[row+1][column-1]=='W' || grid[row+1][column-1]=='C'))
{

if (grid[row+1][column-1]=='W')
area++;

grid[row+1][column-1]='C';

}

//Bottom right
if ((row+1<grid.size()) && (column+1<grid.size()) && (grid[row+1][column+1]=='W' || grid[row+1][column+1]=='C'))
{

if (grid[row+1][column+1]=='W')
area++;

grid[row+1][column+1]='C';

}
}

int main()
{

int nc;
cin >> nc;
grid.push_back(" ");
getline(cin,grid);
getline(cin,grid);

for (int dummy =1; dummy<= nc; dummy++)
{
if (dummy >1 && dummy <=nc)
cout << endl<<endl;

grid.clear();
grid.push_back(" ");
getline(cin,grid);

do
{
grid.push_back(" ");
getline(cin,grid[grid.size()-1]);
} while (grid[grid.size()-1]=='L' || grid[grid.size()-1]=='W');

string position;
position = grid[grid.size()-1];
position = ' ';
position = grid[grid.size()-1];
grid.pop_back();

int aux = 0;
do
{
aux++;
if (aux>=2)
cout <<endl;
int row = position -48 -1;
int column = position -48 -1;

if (grid[row][column] =='W')
{
area++;
}

cout << area;

for (int dummy =0 ; dummy< grid.size();dummy++)
for (int dummy2 = 0; dummy2< grid.size(); dummy2++)
if (grid[dummy][dummy2]=='C'||grid[dummy][dummy2]=='R')
grid[dummy][dummy2]='W';

area =0;
position.clear();
getline(cin,position);
} while (position.size()>0);

}

return 0;
}
``````
I would really apreciate any kind of help, clues possibles. Thx in advance...

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
You missed '\n' at the end of the output.. frandres
New poster
Posts: 2
Joined: Mon Dec 24, 2007 7:34 am
Thx a lot, but I don't think that's the problem I had already tried putting "\n" before return 0; and I keep getting WA.

Any other ideas?

Saul Hidalgo
New poster
Posts: 18
Joined: Wed Jan 03, 2007 2:36 am
Location: Los Teques, Venezuela
Hi! Test with this cases:

Code: Select all

``````2

LLLLLLLLL
LLWWLLWLL
LWWLLLLLL
LWWWLWWLL
LLLWWWLLL
LLLLLLLLL
LLLWWLLWL
LLWLWLLLL
LLLLLLLLL
3 2
7 5

LLLLLLLLL
LLWWLLWLL
10 2
7 5``````
The correct output is:

Code: Select all

``````12
4

0
0``````
You code have

Code: Select all

``````12
4

0
2``````