## 352 - The Seasonal War

Moderator: Board moderators

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

### Re: RE verdict for UVa 352 - The Seasonal War

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

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

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

### Re: RE verdict for UVa 352 - The Seasonal War

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 (77.43 KiB) Viewed 2626 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

change line 23 to:
else return(P[r] = find_root(P[r]));
Check input and AC output for thousands of problems on uDebug!

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

### Re: RE verdict for UVa 352 - The Seasonal War

Thanks!!! Finally Got Accepted!

midorima
New poster
Posts: 1
Joined: Wed Jun 18, 2014 2:21 pm

### UVA - 352 The Seasonal War WA?

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?

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

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

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

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