Codeforces Beta Round #35 (Div. 2) 35C. Fire Again Solution
Problem Link : https://codeforces.com/problemset/problem/35/C
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include<bits/stdc++.h>
using namespace std;
int x[10]= {1,-1,0,0},y[10]= {0,0,1,-1};
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
queue < pair < int, int > > q;
int vis[2001][2001];
int n, m;
cin >> n >> m;
int k;
cin >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) vis[i][j] = 0;
for (int i = 1; i <= k; i++)
{
int a, b;
cin >> a >> b;
q.push(make_pair(a, b));
vis[a][b] = 1;
}
pair < int, int > pr, ans;
while (!q.empty())
{
pr = q.front();
q.pop();
ans = pr;
for (int i = 0; i < 4; i++)
{
int xx = pr.first + x[i];
int yy = pr.second + y[i];
if (xx > 0 && xx <= n && yy > 0 && yy <= m && vis[xx][yy] == 0)
{
vis[xx][yy] = 1;
q.push(make_pair(xx, yy));
}
}
}
cout << ans.first << " " << ans.second << endl;
return 0;
}
No comments