研究出来了!只能对一个测试点的题解
2024-12-31 21:00:39
发布于:湖南
27阅读
0回复
0点赞
#include<iostream>
#include<vector>
#include<climits>
//#define int long long
//#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define QwQ return 0;
#define ll long long
#define endl "\n"
#pragma GCC optimize(2,3)
using namespace std;
//typedef __int128 lll;
ll hmd(ll x1,ll y1,ll x2,ll y2){return abs(x1-x2)+abs(y1-y2);}
signed main(){
//cin.tie();
//cout.tie();
//freopen(" .in","r",stdin);
//freopen(" .out","w",stdout);
cin.tie(nullptr) -> sync_with_stdio(0);
cout.tie(nullptr) -> sync_with_stdio(0);
ll h,w;
cin>>h>>w;
vector<string>m(h);
ll x1,y1,x2,y2;
for(ll i(0);i<h;++i){cin>>m[i];
for(int j(0);j<w;++j){
if(m[i][j]=='o'){if(x1==-1){x1=i;y1=j;}else{x2=i;y2=j;}}}}
int ms=INT_MAX;
for(ll i(0);i<h;++i){
for(ll j(0);j<w;++j){
int d1=hmd(x1,y1,i,j);int d2=hmd(x2,y2,i,j);
ms=min(ms,d1+d2);}}
cout<<ms;
//fclose(stdin),fclose(stdout);
}
这里空空如也
有帮助,赞一个