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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: uva 469

Post by brianfry713 » Wed Jan 08, 2014 3:42 am

Input:

Code: Select all

1

LLLLLLLLL
LLWWLLWLL
LWWLLLLLL
LWWWLWWLL
LLLWWWLLL
LLLLLLLLL
LLLWWLLWL
LLWLWLLLL
LLLLLLLLL
2 7
Output should be 1
Check input and AC output for thousands of problems on uDebug!

sidsi
New poster
Posts: 7
Joined: Sun Mar 23, 2014 5:28 pm

Re: uva 469

Post by sidsi » Fri Apr 04, 2014 7:13 pm

why i am getting WA?? plz help...

#include<stdio.h>
#include<string.h>
void f(int x,int y);
char a[210][210];
int d[210][210];
int j=0,count=0;
int main()
{
int t,x,y,line=0;char s[110];
scanf("%d",&t);
getchar();getchar();
while(t--)
{
int i=0;
while(gets(s)&&strlen(s)>0)
{if ( s[0] == 'L' || s [0] == 'W' ) {
strcpy(a,s);
i++;j=strlen(s);}
else
{
x=s[0]-'0',y=s[2]-'0';
count=0;
memset(d,0,sizeof(d));
f(x-1,y-1);
printf("%d\n",count);}
}
if(t)
printf("\n");
}
return 0;
}
void f(int x,int y)
{int xx=x,yy=y;
int r[]={0,0,1,-1,-1,-1,1,1},c[]={1,-1,0,0,-1,1,-1,1};
if(xx>=0&&yy>=0&&xx<j&&yy<j&&a[xx][yy]=='W'&&d[xx][yy]==0)
{d[xx][yy]=1;
count++;
for(int i=0;i<8;i++)
{xx=x+r;
yy=y+c;
f(xx,yy);
}
}


}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: uva 469

Post by brianfry713 » Fri Apr 04, 2014 9:09 pm

It looks like you figured it out.
Don't use a single getchar() and count on it being a newline.
Check input and AC output for thousands of problems on uDebug!

sidsi
New poster
Posts: 7
Joined: Sun Mar 23, 2014 5:28 pm

Re: uva 469

Post by sidsi » Sat Apr 05, 2014 2:26 pm

thnx :D

thewill
New poster
Posts: 6
Joined: Wed Dec 04, 2013 10:18 am

Re: uva 469

Post by thewill » Sun Jul 20, 2014 9:52 pm

Why WA

#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<deque>
#include<iterator>
#include<assert.h>
#include<bitset>
#include<climits>
#include<ctime>
#include<complex>

using namespace std;

char a[110][110];
int xpt,ypt,dist[110][110],d[]={-1,0,1};

int convert(string s1)
{
int i,l=s1.length(),sum1=0;
for(i=0;i<l;i++)
{
sum1=sum1+(s1-48)*pow(10,l-i-1);
}
return sum1;
}

int main()
{
int i,j,k,l;
int t,spoint,tsum;
string s,temp;
scanf("%d",&t);
getchar();
getchar();
while(t--)
{
temp="";
spoint=1;
for(i=0;i<110;i++)
{
for(j=0;j<110;j++)
{
a[j]='*';
dist[j]=-2;
}
}
while(getline(cin,s)&&(s[0]=='W'||s[0]=='L'))
{
for(i=0;i<s.length();i++)
{
a[spoint][i+1]=s;
}
spoint++;
}
do
{
for(i=0;s!=' ';i++)
{
temp=temp+s;
xpt=convert(temp);
temp="";
}
for(j=i+1;j<s.length();j++)
{
temp=temp+s[j];
ypt=convert(temp);
temp="";
}
queue<int>q1;
queue<int>q2;
q1.push(xpt);
q2.push(ypt);
tsum=1;
dist[xpt][ypt]=0;
while(!q1.empty())
{
int pop1=q1.front();
int pop2=q2.front();
q1.pop();
q2.pop();
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
if(d[j]==0&&d[k]==0)
{
continue;
}
if(a[pop1+d[j]][pop2+d[k]]=='W'&&dist[pop1+d[j]][pop2+d[k]]==-2)
{
tsum++;
q1.push(pop1+d[j]);
q2.push(pop2+d[k]);
dist[pop1+d[j]][pop2+d[k]]=dist[pop1][pop2]+1;
}
}
}
}
if(a[xpt][ypt]=='W')
{
printf("%d\n",tsum);
}
else
{
printf("0\n");
}
for(j=0;j<110;j++)
{
for(k=0;k<110;k++)
{
dist[j][k]=-2;
}
}
getline(cin,s);
}while(s!="");

if(t!=0)
{
printf("\n");
}
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: uva 469

Post by brianfry713 » Mon Jul 21, 2014 8:20 pm

Try solving it without using floating point.
Check input and AC output for thousands of problems on uDebug!

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: uva 469

Post by lighted » Tue Jul 22, 2014 9:48 pm

Change this part. Your code works only when numbers xpt and ypt is one digit number.

Code: Select all

for(i=0;s[i]!=' ';i++)
{
  temp=temp+s[i];
  xpt=convert(temp);
  temp="";
}

for(j=i+1;j<s.length();j++)
{
  temp=temp+s[j];
  ypt=convert(temp);
  temp="";
}
It must be

Code: Select all

for(i=0;s[i]!=' ';i++)
{
  temp=temp+s[i];
}
xpt=convert(temp);
temp="";

for(j=i+1;j<s.length();j++)
{
  temp=temp+s[j];
} 
ypt=convert(temp);
temp="";
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

mhsn06
New poster
Posts: 16
Joined: Tue Apr 01, 2014 7:36 pm

Re: 469 - Wetlands of Florida

Post by mhsn06 » Fri Nov 28, 2014 11:53 pm

Got AC:D
Changed the way.

Thanks to lighted
Last edited by mhsn06 on Sat Nov 29, 2014 11:04 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 469 - Wetlands of Florida

Post by lighted » Sat Nov 29, 2014 1:38 pm

Try input

Code: Select all

1

LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL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LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWL
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWL
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWL
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
2 2
Acc Output

Code: Select all

1
What will be if value of ncc + 'a' and ch becomes greater than 127?
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

bradd123
New poster
Posts: 17
Joined: Thu Jul 03, 2014 11:13 am

Re: 469 - Wetlands of Florida

Post by bradd123 » Sun Dec 28, 2014 11:29 am

Here is my code. It shows WA at 0.046. I can't figure out what is what is wrong here. Please help me.

Code: Select all

Removed after AC, Thank you very much [b]lighted[/b].it is simple input taking problem.
Last edited by bradd123 on Tue Dec 30, 2014 10:02 pm, edited 2 times in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 469 - Wetlands of Florida

Post by lighted » Tue Dec 30, 2014 9:37 am

Input

Code: Select all

1

LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWL
LLLLLLLLLL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LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWL
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWLWL
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
10 10
Acc Output

Code: Select all

1
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

saniatrasel
New poster
Posts: 5
Joined: Tue Apr 07, 2015 11:10 am

Re: 469 - Wetlands of Florida

Post by saniatrasel » Wed May 20, 2015 8:24 am

I got RTE each time I execute the below code...Though all input from Udeg resulted corrected output in my machine. Is there any one who can help me to find the problem:
and my submission id is: 15509188

Code: Select all

#include <stdio.h>
#include<ctype.h>
#include<string.h>
char st[101][101] = {'\0'};
char stCP[101][101] = {'\0'};
int N = 100;
int Ans;
int testCase;

void fill(int x, int y)
{
	if(st[x][y] == 'W')
	{
		st[x][y] = 'L';
		Ans++;
	}
	else
	{
		return;
	}
	if(((x-1)>=0 && (y-1)>=0) && st[x-1][y-1]=='W')
	{
		fill(x-1,y-1);
	}
	if(((x-1)>=0)&&st[x-1][y]=='W')
	{
		fill(x-1,y);
	}
	if((((x-1)>=0)&&(y+1)<N)&& st[x-1][y+1]=='W')
	{
		fill(x-1,y+1);
	}
	if(((y-1)>=0)&& st[x][y-1]=='W')
	{
		fill(x,y-1);
	}
	if((y+1<N)&& st[x][y+1]=='W')
	{
		fill(x,y+1);
	}
	if(((x+1<N)&&(y-1)>=0)&& st[x+1][y-1]=='W')
	{
		fill(x+1,y-1);
	}
	if((x+1<N)&& st[x+1][y]=='W')
	{
		fill(x+1,y);
	}
	if(((x+1<N)&&(y+1)<N)&& st[x+1][y+1]=='W')
	{
		fill(x+1,y+1);
	}	
}
void copyMatrix(int index)
{
	int i = 0;
	while(strlen(st[i])>0)
	{
		memset(st[i],'\0',strlen(st[i]));
		i++;
	}
	for(i=0;i<index;i++)
	{		
		strcpy(st[i],stCP[i]);
	}

	int len = strlen(st[0]);
	//N = ((index-1) * len);

	
	
}
void readCase()
{
	int i = 0;		
	bool flag = false;	
	int k = 0;
	int j = 0;
	while((gets(stCP[i]))&&(strlen(stCP[i]))>0)
	{
		if(isdigit(stCP[i][0]))
		{
			int r,c;
			if(k==0)
			{
				k=i-j;			
			}
			if(sscanf(stCP[i],"%d%d",&r,&c)==2)
			{
				Ans = 0;
				copyMatrix(k);			
				fill(r-1,c-1);
				k = 0;
				j++;
				printf("%d\n",Ans);
			}
		}		
		i++;
	}	
}

int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	getchar();	getchar();
	bool blank = false;	
	while(T--)
	{
		if(blank)
			printf("\n");
		blank = true;
		readCase();		
	}
	return 0;
}

nobi999
New poster
Posts: 2
Joined: Fri May 22, 2015 6:41 am

Re: 469 - Wetlands of Florida

Post by nobi999 » Fri May 22, 2015 6:48 am

Why WA?

Code: Select all

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

#define maxX 110
#define maxY 110

char** pixel;

char waterland[maxX][maxY];

int testcase;

int rowCounter = 0;
int colCounter = 0;


int wetlandCount = 0;

void floodFillUtil(int x, int y)
{
	char prevC = 'W';
	char newC = 'L';

    if (waterland[x][y] != prevC)
        return;
 
	++ wetlandCount;

    waterland[x][y] = newC;
 
    if (  x + 1 < rowCounter )
		floodFillUtil(x+1, y);  // R
	if ( x - 1 >= 0 )
		floodFillUtil(x-1, y);  // L
    if ( y + 1 < colCounter )
		floodFillUtil(x, y+1);  // T
    if ( y - 1 >= 0 )
		floodFillUtil(x, y-1);  // B
    if ( y + 1 < colCounter && x + 1 < rowCounter )
		floodFillUtil(x+1, y+1);  // RT
	if ( y + 1 < colCounter && x - 1 >= 0 )
		floodFillUtil(x-1, y+1);  // LT
    if ( y - 1 >= 0 && x - 1 >= 0 )
		floodFillUtil(x-1, y-1);  // BL
    if ( x + 1 < rowCounter && y - 1 >= 0 )
		floodFillUtil(x+1, y-1);  // BR
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &testcase);
	getchar();
	getchar();
	
	for(int i = 1; i <= testcase; ++i)
	{
		pixel = new char*[maxX];

		rowCounter = 0;
		colCounter = 0;

		int m, n;
		int queryI, queryJ;
		char temp[maxX];

		while(gets(temp) && strlen(temp) > 0)
		{
			if (temp[0] == 'L' || temp[0] == 'W')
			{
				++ rowCounter;
				colCounter = strlen(temp);
				
				pixel[m] = new char[colCounter + 1];
				
				strcpy(pixel[m], temp);
			}
			else
			{
				sscanf(temp, "%d %d" ,&queryI, &queryJ);

				memset(waterland, '\0', sizeof(waterland));

				for (int k = 0; k < rowCounter; ++ k)
					strcpy(waterland[k], pixel[k]); //copy to waterland for BFS

				floodFillUtil(queryI - 1, queryJ - 1);

				printf("%d\n", wetlandCount);
				wetlandCount = 0;
			}

			memset( temp, '\0', sizeof(temp));
		}

		if(i < testcase)
			printf("\n");

	}

	return 0;
}

nobi999
New poster
Posts: 2
Joined: Fri May 22, 2015 6:41 am

469 - Wetlands of Florida

Post by nobi999 » Fri May 22, 2015 7:08 am

Why WA? I have checked all the Random inputs of Udebug. Those are working smoothly.

Code: Select all

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

#define maxX 110
#define maxY 110

char** pixel;

char waterland[maxX][maxY];

int testcase;

int rowCounter = 0;
int colCounter = 0;


int wetlandCount = 0;

void floodFillUtil(int x, int y)
{
	char prevC = 'W';
	char newC = 'L';

    if (waterland[x][y] != prevC)
        return;
 
	++ wetlandCount;

    waterland[x][y] = newC;
 
    if (  x + 1 < rowCounter )
		floodFillUtil(x+1, y);  // R
	if ( x - 1 >= 0 )
		floodFillUtil(x-1, y);  // L
    if ( y + 1 < colCounter )
		floodFillUtil(x, y+1);  // T
    if ( y - 1 >= 0 )
		floodFillUtil(x, y-1);  // B
    if ( y + 1 < colCounter && x + 1 < rowCounter )
		floodFillUtil(x+1, y+1);  // RT
	if ( y + 1 < colCounter && x - 1 >= 0 )
		floodFillUtil(x-1, y+1);  // LT
    if ( y - 1 >= 0 && x - 1 >= 0 )
		floodFillUtil(x-1, y-1);  // BL
    if ( x + 1 < rowCounter && y - 1 >= 0 )
		floodFillUtil(x+1, y-1);  // BR
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &testcase);
	getchar();
	getchar();
	
	for(int i = 1; i <= testcase; ++i)
	{
		pixel = new char*[maxX];

		rowCounter = 0;
		colCounter = 0;

		int m, n;
		int queryI, queryJ;
		char temp[maxX];

		for(m = 0 ; m < maxX && gets(temp) ; m++)
		{
			if(strlen(temp) == 0) {
				break;
			}

			if (temp[0] == 'L' || temp[0] == 'W')
			{
				++ rowCounter;
				colCounter = strlen(temp);
				
				pixel[m] = new char[colCounter + 1];
				
				strcpy(pixel[m], temp);
			}
			else
			{
				sscanf(temp, "%d %d" ,&queryI, &queryJ);

				for (int k = 0; k < rowCounter; ++ k)
					strcpy(waterland[k], pixel[k]); //copy to waterland for BFS

				floodFillUtil(queryI - 1, queryJ - 1);

				printf("%d\n", wetlandCount);
				wetlandCount = 0;
			}

			memset( temp, '\0', sizeof(temp));
		}

		if(i < testcase)
			printf("\n");

	}

	return 0;
}

mosharrafm
New poster
Posts: 2
Joined: Fri May 22, 2015 12:23 pm

Re: 469 - Wetlands of Florida

Post by mosharrafm » Fri May 22, 2015 12:33 pm

Getting TL please Help

Code: Select all

#include<stdio.h>
#include<string.h>

char str[120];
char A[120][120], B[120][120];
int N, count, M;
int rx[]={-1, -1, -1, 0, 0, 1, 1, 1};
int ry[]={-1, 0, 1, -1, 1, -1, 0, 1};

void traverse(int x, int y)
{
	 int dx, dy, i;
	 count++;
	 B[x][y]=1;

	 

	 for( i = 0; i < 8; i++) {
	  dx = x + rx[i];
	  dy = y + ry[i];
	  if(dx>=0 && dx<N && dy>=0 && dy<M && A[dx][dy]=='W' && B[dx][dy]==0) 
		    
            traverse(dx, dy);
	 }


	
}

void readCase()
{
	int i = 0, flag = 0, j, k, p, l;
	//memset(B, 0, sizeof(B));
    memset(A, 0, sizeof(A));

  while(1) {
  gets(str);
  l = strlen(str);
  if(!l) {
	   break;
   }
    if(str[0]=='W' || str[0] == 'L')
	{
		strcpy(A[i], str);
		//strcpy(B[i], A[i]);
		M = l;
	}
   else {
	   sscanf(str, "%d %d", &j, &k);	   
	   if(flag==0) {   
	   N= i;
	   flag = 1;
	   }

	   count=0;
	 if((j-1)>= 0 && (k-1) >=0 && A[j-1][k-1] == 'W') {
		 memset(B, 0, sizeof(B));
         traverse(j-1,k-1);
	 }
	    printf("%d\n", count);

   }
   
	   
 i++;
  }
    
}

int main()
{
  int T, Case;
  scanf("%d", &T);
  getchar();
  getchar();
  for(Case = 1; Case <= T; Case++) {
    readCase();
  }
return 0;
}
Last edited by brianfry713 on Fri Jun 19, 2015 6:22 am, edited 1 time in total.
Reason: Added code blocks

Post Reply

Return to “Volume 4 (400-499)”