Page 3 of 4

Posted: Sat Jul 14, 2007 10:04 am
by chetan
hi all. I am getting RE for this problem
please help me . it works fine on my comp for the sample input.

:cry: :cry: :cry:

Code: Select all


CODE DELETED AFTER AC :D      
    

Posted: Sat Jul 14, 2007 2:40 pm
by Jan
Remove fflush and use

Code: Select all

scanf("%s",str);
instead of

Code: Select all

gets(str); 
Hope it helps.

Posted: Sat Jul 14, 2007 6:01 pm
by chetan
thanks a lot !!!! :D

Posted: Sat Jul 14, 2007 6:06 pm
by SHAHADAT
BETOVSKY

use your array a[27][27] as char and try to input as

Code: Select all

for(i=1;i<=n;i++)
{ 
	scanf("%s", &a[i][1]); 
} 
	
instead of

Code: Select all

for(i=1;i<=n;i++)
{
     scanf("%d", &linha); 
     for(j=1;j<=n;j++){ 
     a[i][j]=linha%10; 
     linha=linha/10; 
    } 

} 


because int is not sufficient of input as a number of 25 digits.
-----------------------------------------------------------------
LIFE IS COMBINED WITH JOY AND SORROW.IT IS NOT ONLY FOR SITTING IN A ROOM AND TYPING CODE.

Posted: Tue Nov 20, 2007 7:51 pm
by quinine
Shaka_RDR wrote:sorry, my algorithm was wrong... i should've used recursive to solve this problem (but i didn't, cause i want to prove that i can solve this problem using iteration not recursive)...

to any body who still have WA , i suggest you to check with this sample input :

INPUT :

5
00000
01010
01010
01110
00000

OUTPUT :
Image number 1 contains 1 war eagles.
Yes! That was my problem too. I'm curious though, is there any way to make breadth-first scanning (the iteration thing) work for such cases?

Re: 352 The Seasonal War

Posted: Wed Jun 11, 2008 12:55 pm
by vivgrn
Can anyone please tell me whats wrong in this code because iam always getting a wrong answer.

Code: Select all

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

using namespace std;
void func( vector < vector<char>  > &arr,int i,int j,int num);
int main()
{
    int num;
    int xcase=0;
    while(cin>>num)
    {
                   xcase++;
                   const int p=num;
                   vector< vector<char> > arr(p, vector<char> (p));
                   for(int i=0;i<num;i++)
                   {
                           for(int j=0;j<num;j++)
                           {
                                   char ch;
                                   cin>>ch;
                           arr[i][j]=ch;
                           }
                   }
                   int sum=0;
                   for(int i=0;i<num;i++)
                   {
                           for(int j=0;j<num;j++)
                           {
                           if(arr[i][j]=='1')
                           {
                                             sum++;
                                             func(arr,i,j,num);
                           }
                            }
                   }
                   if(sum==1)
                   cout<<"Image number "<<xcase<<" contains "<<sum<<" war eagle."<<endl;
                   else
                   cout<<"Image number "<<xcase<<" contains "<<sum<<" war eagles."<<endl;
                   
    }
return 0;                   
}
    
void func( vector < vector<char>  > &arr,int i,int j,int num)

{
     arr[i][j]='0';
     if(i-1>=0 &&j-1 >=0)
     {
               if(arr[i-1][j-1]=='1')
               func(arr,i-1,j-1,num);
     }
     if(j-1>=0)
     {
               if(arr[i][j-1]=='1')
               func(arr,i,j-1,num);
     }
     if(i+1<num &&j-1>=0)
     {
                if(arr[i+1][j-1]=='1')
                func(arr,i+1,j-1,num);
     }
     if(i-1>0)
     {
        if(arr[i-1][j]=='1')
               func(arr,i-1,j,num);
     }  
     if(i+1<num)
     {
                if(arr[i+1][j]=='1')
                func(arr,i+1,j,num);
     }
     if(j+1<num &&i-1>=0)
     {
              if(arr[i-1][j+1]=='1')
              func(arr,i-1,j+1,num);
     }
     if(j+1<num)
     {
                if(arr[i][j+1]=='1')
                func(arr,i,j+1,num);
     }
     if(j+1<num && i+1 <num)
     {
                if(arr[i+1][j+1]=='1')
                func(arr,i+1,j+1,num);
     }
}
Awaiting your reply

Thanks in advance

Re: 352 The Seasonal War

Posted: Sat Jan 03, 2009 9:33 am
by golden eye
cut

352 The Seasonal War WA

Posted: Tue Aug 25, 2009 9:31 pm
by bm_anas
hi,could anyone give some input,for that my prog goes wrong.Thnx in advance.

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

int main()
{
int n,i,j,total,used[30][30],flag,num=1,max,len;
char input[30][30];

while(scanf("%d",&n)==1)
{
for(i=0,max=0;i<n;i++)
{
scanf("%s",input);
len=strlen(input);
if(len>max)
max=len;

}

for(i=0;i<=n;i++)
for(j=0;j<=max;j++)
used[j]=0;

for(i=0;i<n;i++)
{
len=strlen(input);
for(len;len<max;len++)
input[len]='0';
input[len]=0;
}

total=0;

for(i=0;i<n;i++)
{
for(j=0;j<len;j++)
{
if(input[j]=='1')
{
if(i==n-1)//last row
{
if(!used[j])
total++;
if(j!=len-1)
used[j+1]=1;
used[j]=1;
}

else//before last
{
flag=0;
if(!used[i][j])
{
flag=1;


}


if(j==0)//first column
{
if(flag)
total++;
used[i+1][j]=1;
used[i+1][j+1]=1;
}
else if(j==len-1)//last column
{
if(input[i+1][j-1]=='1')
if(used[i+1][j-1])
flag=0;
if(flag)
total++;
used[i+1][j-1]=1;
used[i+1][j]=1;
}
else//middle columns
{
if(input[i+1][j-1]=='1')
if(used[i+1][j-1])
flag=0;
if(flag)
total++;
used[i+1][j]=1;
used[i+1][j-1]=1;
used[i+1][j+1]=1;

}
if(j!=len-1)//not last column.
used[i][j+1]=1;

}


}
}
}
printf("Image number %d contains %d war eagles. \n",num++,total);
}

return 0;
}

Re: 352 The Seasonal War WA

Posted: Mon Feb 08, 2010 11:53 am
by saiful_sust
This is a normal floodfill problem...

Try to do this ....

AND After ACC PLZ remove ur code.... :D

352 The Seasonal War wrong answer ??

Posted: Sat Nov 09, 2013 1:06 pm
by mntamim
ive tried every single test case on the forum and that i can think of and all are correct

may i please get a hint or some help as to what im missing

i keep getting WA

Code: Select all

#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <list>
#include <vector>
#include <math.h>

using namespace std;

char** matrix;
int eagles;
int n;

void explore(int i, int j)
{
	if(i<0 || j<0 || i>=n || j>=n)
		return;

	if(matrix[i][j]=='0')
		return;

	matrix[i][j] = '0';

	explore(i-1,j-1);
	explore(i+1,j-1);
	explore(i-1,j+1);
	explore(i+1,j+1);

	explore(i-1,j);
	explore(i+1,j);
	explore(i,j-1);
	explore(i,j+1);

}

int main()
{
	freopen("Bumble.in","r",stdin);  // Bumble.in

	int num=1;

	char temp[50];


	while(scanf("%d",&n)!=EOF)
	{
		matrix = new char*[n];
		for(int i=0 ; i<n ; i++)
		{
			matrix[i] = new char[n];
			scanf("%s",matrix[i]);
		}

		eagles = 0;
		for(int i=0 ; i<n ; i++)
		{
			for(int j=0 ; j<n ; j++)
			{
				if(matrix[i][j]=='1')
				{
					eagles++;
					explore(i,j);
				}
			}
		}

		printf("Image number %d contains %d war eagles.\n",num,eagles);
		num++;
	}
	return 0;
}

Re: 352 The Seasonal War wrong answer ??

Posted: Sat Nov 09, 2013 1:17 pm
by mntamim
wow this is soo stupid
ive been at this problem for 2 days
it clearly says in the problem the input should be from file "Bumble.in"

Re: 352 The Seasonal War wrong answer ??

Posted: Mon Nov 11, 2013 11:29 pm
by brianfry713
No matter what the problem statement says on this judge always read from stdin and write to stdout.

RE verdict for UVa 352 - The Seasonal War

Posted: Sat Jan 18, 2014 7:10 pm
by shikhorroy
Where is the problem? Why am I getting RE? Help me please...

Code: Select all

#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<cstring>
#include<climits>

#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<sstream>
#include<bitset>
#include<algorithm>
using namespace std;

#define MAX 100
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef map<string, int> msi;
#define REP(i, b, e)\
    for(int i = int(b); i <= int(e); i++)
#define TRvi(c, it)\
    for(vi::iterator it = (c).begin(); it != (c).end(); ++it )
#define TRvii(c, it)\
    for(vii::iterator it = (c).begin(); it != (c).end(); ++it )
#define sf scanf
#define pf printf
#define si(x) sf("%d",&x)
#define in(x) cin>>x
#define out(x) cout<<(x)
#define ln length()
#define sz size()
#define clr clear()
#define pb push_back
#define mp make_pair
#define READ(f) freopen(f, "r", stdin)
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define WHITE 0
#define BLACK 1
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
vi adjList[MAX];
int isTook[MAX];
int nodes, edges;
int side, cs = 0;
bool yes(int x)//Weather within boundery or not.
{
    return (x > -1 && x < side);
}
void dfs_func(int src)
{
    isTook[src] = BLACK;
    TRvi(adjList[src], it)
    if(isTook[*it] == WHITE)
        dfs_func(*it);
}
void CLR(int n)
{
    REP(i, 0, n - 1) adjList[i].clr;
}
int main()
{
//    READ("in.txt");
    while(si(side) != EOF)
    {
        getchar();
        int node = 0;
        string str, tstr;
        map<pii, int> m;
        REP(i, 0, side - 1)
        {
            getline(cin, str);
            REP(j, 0, side - 1)
            {
                if(str[j] == '1')
                {
                    if(m.find(mp(i, j)) == m.end())
                        m[mp(i, j)] = node++;
                    if(yes(j - 1) && str[j - 1] == '1')//if front is a node and has '1'.
                    {
                        adjList[m[mp(i, j - 1)]].pb(m[mp(i, j)]);
                        adjList[m[mp(i, j)]].pb(m[mp(i, j - 1)]);
                    }
                    if(yes(i - 1))//if there is an upper row.
                    {
                        if(yes(j - 1) && tstr[j - 1] == '1')
                        {
                            adjList[m[mp(i - 1, j - 1)]].pb(m[mp(i, j)]);
                            adjList[m[mp(i, j)]].pb(m[mp(i - 1, j - 1)]);
                        }
                        if(tstr[j] == '1')
                        {
                            adjList[m[mp(i - 1, j)]].pb(m[mp(i, j)]);
                            adjList[m[mp(i, j)]].pb(m[mp(i - 1, j)]);
                        }
                        if(yes(j + 1) && tstr[j + 1] == '1')
                        {
                            adjList[m[mp(i - 1, j + 1)]].pb(m[mp(i, j)]);
                            adjList[m[mp(i, j)]].pb(m[mp(i - 1, j + 1)]);
                        }
                    }
                }
            }
            tstr = str;
        }
        int tWar = 0;
        REP(i, 0, node -1)isTook[i] = WHITE;
        REP(nd, 0, node - 1)
        {
            if(isTook[nd] == WHITE)
            {
                tWar++;
                dfs_func(nd);
            }
        }
        pf("Image number %d contains %d war eagles.\n", ++cs, tWar);
        CLR(node);
    }
    return 0;
}

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Mon Jan 20, 2014 9:22 pm
by brianfry713
Input:

Code: Select all

1
1
21
000101001000011100100
011011100100100000101
100010011010111000010
000001111010011000100
101100111110000110011
010010011001011000100
100011010101100001110
011110000000001100110
000001010011110110110
110000111110010110111
010001000111101010101
101010000101001111001
111110110101000001001
100111011110000011101
000010110110100001100
100110000001000001110
100101111101000000000
101111100110010101011
111010000111010100111
110100000101101101110
011001011000011111111
17
01110001111011001
10110101000111110
01110001011010111
10011110011001010
11011110100101000
11111100100010101
11001101001001000
11110110100001101
11101100011011100
00110011110010011
00000011000110110
00011111001010011
01100000111111111
10101101101110110
11000111000011110
11110011110100010
01100000000110000
15
001000010011001
101100100000000
011111110111011
101100110100101
000111000011100
110000010100100
001010111110000
010100100110110
010101110011110
101111000001010
110100101100110
110001001001111
000011001101011
000000101001000
100100000110111
5
11010
00011
11111
01011
00101
23
10000100101100011101111
10111100010111100110110
11010111010111010111000
01111011101101011111001
10001011100011100101111
00111100100101010000110
01101110111111110101110
11011001011000111000111
11111001111001001011010
10101010111000011100000
01011101000011000111111
01101101100011001010000
00111011000011100100010
01011011000010100100011
01011001110000011011110
01100101110010101000110
00001111110011000101010
10010100000010101001111
00101111001001011111010
11110010011100011001111
00011110001101000111101
01010101110001101110011
01000001011110001100111
2
01
11
11
00110110111
00011000100
10010101011
10010001111
00000101111
10100101000
01011100001
11101010110
11000000011
00010111000
10100111100
1
0
12
110101100001
011010100110
000001110110
100110010111
100011010000
111100111100
001010111110
110110111001
101011010111
110001110100
111001111011
010000111001
12
110010111110
000111101101
010010001000
011100110101
011001101010
011111111101
110010111111
010111010101
010100101100
010101110101
000010100110
100000100110
12
011100101101
001110000101
001111101011
111001111101
111101001110
100010101001
010101010110
010111001000
010110110110
010011010011
111111100010
001000100111
3
100
010
101
12
010010110011
010011101111
101011110111
101100001011
101010001110
001010000111
101000101100
101000000111
111000110011
111001010100
100101010110
001011100000
2
01
00
15
010010011011111
010110110111111
010001001000111
000111111000110
001001011110101
001011010110100
100100001010000
101110011000010
010001101001101
100011110010111
100000111001110
100111000001010
110011000100101
110101001001101
110011101111001
15
101000001001100
100111010111111
111010100001101
111101000011011
100001011100010
111101011010011
101110011001001
000110011111110
101010001000100
000011110000111
000111111011011
111100111111111
111100010011100
110000111010001
110000111111001
8
10100110
01101100
10111000
11110001
01110010
00111100
11001010
00101011
12
100110111110
110010101100
001010001000
010001010010
100010000101
000100111110
011101111111
101111010000
001010000110
001010100010
111100000101
001000000101
18
110100101001001011
010011001101000011
001011111110010011
111100010011100001
110100101111100011
010001011001111101
100111001011110100
100000011100000011
110111010000110100
101010010001010001
100111000010100001
011011110111101100
000101111000101010
100001110000110100
110010010111010010
101101110110000001
010000001000000110
010101101101100111
AC output:

Code: Select all

Image number 1 contains 1 war eagles.
Image number 2 contains 3 war eagles.
Image number 3 contains 5 war eagles.
Image number 4 contains 6 war eagles.
Image number 5 contains 2 war eagles.
Image number 6 contains 3 war eagles.
Image number 7 contains 1 war eagles.
Image number 8 contains 8 war eagles.
Image number 9 contains 0 war eagles.
Image number 10 contains 2 war eagles.
Image number 11 contains 3 war eagles.
Image number 12 contains 2 war eagles.
Image number 13 contains 1 war eagles.
Image number 14 contains 2 war eagles.
Image number 15 contains 1 war eagles.
Image number 16 contains 3 war eagles.
Image number 17 contains 3 war eagles.
Image number 18 contains 1 war eagles.
Image number 19 contains 5 war eagles.
Image number 20 contains 6 war eagles.

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Wed Jan 22, 2014 5:45 pm
by shikhorroy
Thanks....I got AC. :)