1012 – Guilty Prince

Problem Link

Hints: Run Bfs to check for land
First : store initial position of prince
then run from this position
highest only 4 move can be use (-1,0),(1,0),(0,-1),(0,1)
and print the count;

 

View Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll n,m,co=1;
char s[21][21];
int vis[21][21];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

ll bfs(ll sx,ll sy)
{
vis[sx][sy]=1;
for(ll i=0;i<4;i++) { ll tx=sx+dx[i]; ll ty=sy+dy[i]; if( tx>=0 &&tx=0 &&ty>t;
while(t–)
{

cin>>n>>m;

for(int i=0;i<m;i++)
scanf(“%s”,&s[i]);
ll sx=0,sy=0;

memset(vis,0,sizeof vis);
int f=0;
for(ll i=0;i<m;i++)
{

for(ll j=0;j<n;j++)
{if(s[i][j]==’@’)
{
sx=i;
sy=j;// pair<int,int> can be used
f=1;
co=1; //for each testcase
break; }
}

if(f==1)
break;

}

ll d=0;

d=bfs(sx,sy);
cout<<“Case “<<cs++<<“: “<<d<<endl;
}
return 0;
}

 

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in lightoj and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s