Critical t get the question but easy to solve. Problem asks to find the maximum length of minimum distance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include <iostream> #include <cstdio> #include <vector> #include <stack> #include <cmath> #include <cstring> #include <fstream> #include <string> #include <algorithm> #define INF 100000000 #define ll long long using namespace std; struct Cord{ int x,y; }; int M; char gr[1010][1010]; char s[1010][1010]; vector<Cord> Ones,Threes; int main() { Cord tmp; int MX,dist,MN; while(scanf("%d",&M)!=EOF) { getchar(); Threes.clear(); Ones.clear(); for(int i=0;i<M;i++) { scanf("%s",s[i]); for(int j=0;j<strlen(s[i]);j++) { if(s[i][j]=='1') { tmp.x = i; tmp.y = j; Ones.push_back(tmp); } if(s[i][j]=='3') { tmp.x = i; tmp.y = j; Threes.push_back(tmp); } } } MX = -1; for(int i=0;i<Ones.size();i++) { MN = INF; for(int j=0;j<Threes.size();j++) { dist = abs(Ones[i].x-Threes[j].x)+abs(Ones[i].y-Threes[j].y); if(dist<MN) MN =dist; } if(MX<MN) MX = MN; } printf("%d\n",MX); } return 0; } |