Page 4 of 4

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Tue Feb 25, 2014 11:56 am
by blackheartadhar
Getting WA. Please Help!

Code: Select all

Removed After AC!

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Tue Feb 25, 2014 9:43 pm
by brianfry713
Try running your code on the sample input.

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Tue Feb 25, 2014 9:54 pm
by blackheartadhar
I've tried not only the sample test case but also the 20 test cases you have given above. I've attached a screenshot of the output generated by my code.

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Thu Feb 27, 2014 1:47 am
by brianfry713
change line 23 to:
else return(P[r] = find_root(P[r]));

Re: RE verdict for UVa 352 - The Seasonal War

Posted: Thu Feb 27, 2014 4:36 pm
by blackheartadhar
Thanks!!! Finally Got Accepted! :)

UVA - 352 The Seasonal War WA?

Posted: Wed Jun 18, 2014 2:35 pm
by midorima
I'm still getting WA, but it seems that my code is correct, Please help me!!

this is my code :

Code: Select all

#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int dr[] = {1,1,0,-1,-1,-1,0,1};
int dc[] = {0,1,1,1,0,-1,-1,-1};
int N;
char grid[25][25];

bool isSafe(int r, int c){
    if (r<0 || r>=N || c<0 || c>=N) return false;
    return true;
}

void floodfil(int r, int c, char c1, char c2){
    if (grid[r][c]== c1 && isSafe(r,c)){
        grid[r][c] = c2;
        for (int d=0;d<8;d++)
            floodfil(r+dr[d], c+dc[d], c1, c2);
    }
}

int main(){
    freopen("Bumble.in","r",stdin);
    freopen("Bumble.out","w",stdout);
    int cases = 1;
    while (cin>>N){
        for (int i=0;i<N;i++)
            scanf ("%s",grid[i]);

        int counte = 0;
        for (int i=0;i<N;i++){
            for (int j=0;j<N;j++){
                if (grid[i][j]=='1'){
                    floodfil(i,j,'1','0');
                    counte++;
                }
            }
        }
        printf ("Image number %d contains %d war eagles.\n",cases,counte);
        cases++;
    }
    return 0;
}

Re: UVA - 352 The Seasonal War WA?

Posted: Wed Jun 18, 2014 11:19 pm
by brianfry713
Don't read and write to files.

Re: 352 - The Seasonal War

Posted: Fri Aug 29, 2014 10:18 pm
by tooorjo
why wa?

Code: Select all

#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int n;
char pic[30][30];
void bfs(int i, int j)
{
    queue<int> Q;
    int u,v,w;
    Q.push(i*n+j);
    pic[i][j]='0';
    while(!Q.empty())
    {
        u=Q.front();
        v=u/n;
        w=u%n;
        for(int a=v-1;a<=v+1;a++)
        {
            if(a<0 || a>=n) continue;
            for(int b=w-1;b<=w+1;b++)
            {
                if(b<0 || b>=n) continue;
                if(pic[a][b]=='1')
                {
                    pic[a][b]='0';
                    Q.push(a*n+b);
                }
            }
        }
        Q.pop();
    }

}

int main()
{
    int i,c,kase=0;
    while(scanf("%d",&n)!=EOF)
    {
        c=0;
        for(i=0;i<n;i++)
        scanf("%s",&pic[i]);

    for(i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            if(pic[i][j]=='1')
            {
                bfs(i,j);
                c++;
            }
        }
    if(c<2)
        cout<<"Image number "<<++kase<<" contains "<< c<<" war eagle."<<endl;
    else
        cout<<"Image number "<<++kase<<" contains "<< c<<" war eagles."<<endl;
    }

    return 0;
}

Re: 352 - The Seasonal War

Posted: Sun Aug 31, 2014 6:49 pm
by lighted
You shouldn't do what is not said in problem's description. Remove checking c < 2

Code: Select all

if(c<2)
        cout<<"Image number "<<++kase<<" contains "<< c<<" war eagle."<<endl;
else
        cout<<"Image number "<<++kase<<" contains "<< c<<" war eagles."<<endl;
It must be

Code: Select all

        cout<<"Image number "<<++kase<<" contains "<< c<<" war eagles."<<endl;
Don't forget to remove your code after getting accepted. 8)

Re: 352 - The Seasonal War

Posted: Sat Apr 04, 2015 12:20 pm
by uDebug
brianfry713, Derk,
Thanks for the great test cases!