352 - The Seasonal War

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

Moderator: Board moderators

blackheartadhar
New poster
Posts: 10
Joined: Mon Nov 04, 2013 10:14 am

Re: RE verdict for UVa 352 - The Seasonal War

Post by blackheartadhar »

Getting WA. Please Help!

Code: Select all

Removed After AC!
Last edited by blackheartadhar on Thu Feb 27, 2014 4:37 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: RE verdict for UVa 352 - The Seasonal War

Post by brianfry713 »

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!
blackheartadhar
New poster
Posts: 10
Joined: Mon Nov 04, 2013 10:14 am

Re: RE verdict for UVa 352 - The Seasonal War

Post 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.
Attachments
Untitled.jpg
Untitled.jpg (77.43 KiB) Viewed 4320 times
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: RE verdict for UVa 352 - The Seasonal War

Post by brianfry713 »

change line 23 to:
else return(P[r] = find_root(P[r]));
Check input and AC output for thousands of problems on uDebug!
blackheartadhar
New poster
Posts: 10
Joined: Mon Nov 04, 2013 10:14 am

Re: RE verdict for UVa 352 - The Seasonal War

Post by blackheartadhar »

Thanks!!! Finally Got Accepted! :)
midorima
New poster
Posts: 1
Joined: Wed Jun 18, 2014 2:21 pm

UVA - 352 The Seasonal War WA?

Post 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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA - 352 The Seasonal War WA?

Post by brianfry713 »

Don't read and write to files.
Check input and AC output for thousands of problems on uDebug!
tooorjo
New poster
Posts: 1
Joined: Fri Aug 29, 2014 9:34 pm

Re: 352 - The Seasonal War

Post 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;
}
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 352 - The Seasonal War

Post 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)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 352 - The Seasonal War

Post by uDebug »

brianfry713, Derk,
Thanks for the great test cases!
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
Post Reply

Return to “Volume 3 (300-399)”