Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- using namespace std;
- const int dx[4]={1,0,-1,0};
- const int dj[4]={0,1,0,-1};
- int main()
- {
- int n,m,k;
- cin>>n>>m;
- cin>>k;
- char x[n][m];
- vector<pair<int,int>>v;
- for(int i = 0;i<n;i++){
- for(int j = 0;j<m;j++){
- cin>>x[i][j];
- if(x[i][j]=='C'){
- v.push_back(make_pair(i,j));
- }
- }
- }
- int si;
- int sj;
- int cnt[n][m];
- for(int i = 0;i<n;i++){
- for(int j = 0;j<m;j++){
- cnt[i][j]=0;
- }
- }
- for(int i = 0;i<v.size();i++){
- queue<int>q;
- si=v[i].first;
- sj=v[i].second;
- q.push(si);
- q.push(sj);
- q.push(0);
- vector<vector<bool>>visited(n,vector<bool>(m,false));
- while(!q.empty()){
- int ci=q.front();
- q.pop();
- int cj=q.front();
- q.pop();
- int dist=q.front();
- q.pop();
- for(int p = 0;p<4;p++){
- int ti=ci+dx[p];
- int tj=cj+dj[p];
- if(ti>=0 && ti<n && tj>=0 && tj<m && x[ti][tj]!='#' && visited[ti][tj]==false && dist+1<=k){
- visited[ti][tj]=true;
- q.push(ti);
- q.push(tj);
- q.push(dist+1);
- cnt[ti][tj]++;
- }
- }
- }
- }
- int najgolem=0;
- int ri;
- int rj;
- for(int i = 0;i<n;i++){
- for(int j = 0;j<m;j++){
- if(cnt[i][j]>najgolem and x[i][j] != 'C'){
- najgolem=cnt[i][j];
- ri=i;
- rj=j;
- }
- }
- }
- cout<<ri + 1<<" "<<rj + 1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement