Problem - D - Codeforces
大致题目意思:找#的圆心
#include<bits/stdc++.h>
typedef long long ll;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const ll N=1e2+1;
char a[N][N];
using namespace std;
int main()
{
IOS;
int t;
cin>>t;
while(t--)
{
ll fsth=0,fstl=0;
ll n,m;
cin>>n>>m;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=m;j++)
{
if(a[i][j]=='#')
{
fsth=i;
fstl=j;
break;
}
}
if(fsth!=0) break;
}
//cout<<fsth<<"hang";
ll x,y;
for(ll i=fsth;i<=n;i++)
{
if(a[i][fstl]!='#')
{
x=i-1;
break;
}
if(i==n) x=n;
}
//cout<<x<<"zheli";
y=(x+fsth)/2;
cout<<y<<" "<<fstl;
cout<<endl;
}
return 0;
}
存在问题:数组开太大,2e5
ac代码
#include<bits/stdc++.h>
typedef long long ll;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const ll N=1e2+1;
using namespace std;
int main()
{
IOS;
int t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
ll mx[2]={1,1},mi[2]={n,m};
for(ll i=1;i<=n;i++)
{
string a;
cin>>a;
for(ll j=0;j<m;j++)
{
if(a[j]=='#')
{
mx[0]=max(mx[0],i);
mx[1]=max(mx[1],j+1);
mi[0]=min(mi[0],i);
mi[1]=min(mi[1],j+1);
}
}
}
cout<<(mx[0]+mi[0])/2<<" "<<(mx[1]+mi[1])/2;
cout<<endl;
}
return 0;
}