ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1250. Sea Burial

What's wrong with my program??? I want TEST #12 of Problem 1250
Posted by lixiang 26 Jun 2011 21:23
#include<stdio.h>
#include<iostream>
using namespace std;
const int maxn=505,maxq=50005;
const int  dx[9]={0,-1,1,0,0,-1,-1,1,1},dy[9]={0,0,0,-1,1,-1,1,1,-1};
const char sea='.',land='#',sea1=' ',land1='&';
char map[maxn][maxn];
int qx[maxq],qy[maxq],m,n,x,y,u,h,f,r,i,j;
int ans;
void init(){
     scanf("%d",&n);scanf("%d",&m);scanf("%d",&y);scanf("%d",&x);
     for(i=0;i<=n+1;i++)map[0][i]=land,map[m+1][i]=land;
     for(i=1;i<=m;i++)map[i][0]=land,map[i][n+1]=land;
     for(i=1;i<=m;i++)cin>>(map[i]+1);
}
void floodfill(int x,int y,char c1,char c2,char c3,int dir){
     int  i;
     f=0;r=1;qx[1]=x;qy[1]=y;map[x][y]=c3;
     do{
        f++;if(f>maxq)f=1;
        for(i=1;i<=dir;i++)
          if(map[qx[f]+dx[i]][qy[f]+dy[i]]==c1||map[qx[f]+dx[i]][qy[f]+dy[i]]==c2)
          {r++;if(r>maxq)r=1;qx[r]=qx[f]+dx[i];qy[r]=qy[f]+dy[i];map[qx[r]][qy[r]]=c3;}
        }while(f!=r);
}
void work(){
     floodfill(x,y,sea,sea,sea1,8);
     floodfill(0,0,sea,land,land1,4);
     for(int i=1;i<=m;i++)
       for(int j=1;j<=n;j++)
         if(map[i][j]==land){ans++;floodfill(i,j,land,land,land1,4);}
}
void print(){
     printf("%d\n",ans);
}
int main(){
    init();
    work();
    print();
    return 0;
}
Re: What's wrong with my program??? I want TEST #12 of Problem 1250
Posted by Juliet 27 Jun 2011 14:40
Apply the GOOD JOB for College ACMers to Make Large Money and Become a Millionaire

Hello, We need large no. of dedicated and hard working ACMers. The payment is good so we need ACMers to be efficient. All you have to do to get the job is to sign up at our websites. The link of our websites are given below.

http://www.PaisaLive.com/register.asp?3556638-4847933

After the registration, a confirmation email will be sent to your specified email address. Please click on the link inside the confirmation email to activate your account and recieve ACM work instantly. For any other queries you can mail the administrator.

Miss Juliet

Admin paisalive.com