469 - Wetlands of Florida

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

469-wetlands of florida... please help me...

Post by litehiro » Thu Sep 02, 2004 7:12 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[1] in ['1'..'9'] = false then
temp:=copy(temp,2,length(temp)-1);
until temp[1] 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
readln(totcase);
readln;
for cs:=1 to totcase do
begin
if cs>1 then writeln;

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

temp:='';
repeat
readln(temp);
until temp<>'';

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

repeat

temp:='';
repeat
readln(temp);
until temp<>'';

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

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

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

readln(temp);


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.

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

please reply.... thanks a lot!!!

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

469 RTE. HELP REQUIRED!!!!

Post by shihabrc » Sun Oct 09, 2005 8:46 am

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[2][8];
int count;
int row,col;
char tempin[200];

void initk(void){
	k[0][0]=-1;
	k[1][0]=0;
	k[0][1]=1;
	k[1][1]=0;
	k[0][2]=0;
	k[1][2]=1;
	k[0][3]=0;
	k[1][3]=-1;
	k[0][4]=-1;
	k[1][4]=1;
	k[0][5]=-1;
	k[1][5]=-1;
	k[0][6]=1;
	k[1][6]=1;
	k[0][7]=1;
	k[1][7]=-1;
}

struct input {
	char pixel[200];
	int visited[200];
};

struct input in[200];

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

void main(void){
	int n,i,p,r[200],c[200],m,q;
	char t[2];
	scanf("%d", &n);
	gets(t);
	gets(t);
	initk();
	for(i=0;i<n;i++){
		initmat();
		gets(in[0].pixel);
		col=strlen(in[0].pixel);
		p=1;
		while(gets(in[p].pixel)!=NULL){
			if(in[p].pixel[0]=='\0' || in[p].pixel[0]=='\n') break;
			if(isdigit(in[p].pixel[0])) {
				r[0]=atoi(strtok(in[p].pixel," "));
				c[0]=atoi(strtok(NULL," "));
				break;
			}
			p++;
		}
		m=1;
		while(gets(tempin)!=NULL){
			if(tempin[0]=='\n' || tempin[0]=='\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[0][p];
		nc=v+k[1][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???

Post by pregunton2 » Wed Oct 26, 2005 6:43 pm

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

User avatar
Roby
Experienced poster
Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia
Contact:

Post by Roby » Fri Nov 18, 2005 12:37 pm

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... :D

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

469...why TLE???

Post by asif_rahman0 » Mon Apr 24, 2006 2:20 pm

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
Location: Bangladesh
Contact:

Re: 469...why TLE???

Post by mamun » Mon Apr 24, 2006 3:31 pm

asif_rahman0 wrote:so funny thing is i m gettign TLE.
Not so funny :P

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

Post by asif_rahman0 » Mon Apr 24, 2006 7: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 ...

Post by bekerpico » Wed Aug 02, 2006 3:51 am

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[450][450] 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 :D ... cause k >0 and not specified ....
PicO's reply

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

Why WA??

Post by ranban282 » Tue Mar 27, 2007 5:54 pm

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[0].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[0].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[0].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[0].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

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo » Tue Mar 27, 2007 6:23 pm

I used this form to take the input

Code: Select all

int tcas,R,C;
char temp[128];

scanf("%d\n",&tcas);
while(tcas--)
{
	while(1)
	{
	gets(temp);
	if(temp[0]!='W'&&temp[0]!='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

Post by frandres » Mon Dec 24, 2007 7:39 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;

void getHowManyAdjacentWaterTitles(int row, int column)
{
   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';

      getHowManyAdjacentWaterTitles(row-1, column);
   }

   //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';

      getHowManyAdjacentWaterTitles(row+1, column);
   }

   //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';

      getHowManyAdjacentWaterTitles(row, column-1);
   }

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

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

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

      getHowManyAdjacentWaterTitles(row, column+1);
   }

   //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';

      getHowManyAdjacentWaterTitles(row-1, column-1);
   }

   //Upper right
   if ((row-1>=0)&& (column+1<grid[0].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';

      getHowManyAdjacentWaterTitles(row-1, column+1);
   }

   //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';

      getHowManyAdjacentWaterTitles(row+1, column-1);
   }

   //Bottom right
   if ((row+1<grid.size()) && (column+1<grid[0].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';

      getHowManyAdjacentWaterTitles(row+1, column+1);
   }
}


int main()
{

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

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

      grid.clear();
      grid.push_back(" ");
      getline(cin,grid[0]);

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

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

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

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

         cout << area;

         for (int dummy =0 ; dummy< grid.size();dummy++)
            for (int dummy2 = 0; dummy2< grid[0].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

Post by helloneo » Mon Dec 24, 2007 8:11 am

You missed '\n' at the end of the output.. :-)

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

Post by frandres » Mon Dec 24, 2007 5:11 pm

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

Post by Saul Hidalgo » Mon Dec 31, 2007 11:03 am

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
I hope that is help you.

User avatar
vahid sanei
Learning poster
Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

Re: 469-wetlands of florida... please help me...

Post by vahid sanei » Sat Feb 21, 2009 5:44 pm

I dont know anything about Pascal
but i think your code dont print blank line between consecutive outputs .
Impossible says I`m possible

Post Reply

Return to “Volume 4 (400-499)”