- 笨笨的学校距离
- 2009-10-31 14:08:32 @
谁有题解!!!!
2 条评论
-
Vijos永远NB (郑灏轩) LV 10 @ 2021-12-23 20:25:31
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<cmath>
#include<cstring>
#define maxa 200+10
#define FOR(i,x,y) for(i=x;i<=y;++i)
using namespace std;
struct point
{
int x,y;
};
struct node
{
string name;
vector<point> v;
double d;
}e[maxa];
double dis(point p,point q)
{
return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}
bool comp(node p,node q)
{
if(p.d!=q.d)
{
return p.d<q.d;
}
else
return p.name<q.name;
}
int main()
{
int n,m,l;
scanf("%d%d%d",&n,&m,&l);
int mod = 260;
char s[mod];
int i,j,k;
for(i=0;i<n;++i)
{scanf("%s",s);
for(j=0;j<m;++j)
if(s[j]=='#')
{
e[0].v.push_back(point{i,j});
}
}
FOR(i,1,l)
{
scanf("%s",s);
e[i].name = s;
FOR(k,0,n-1){
scanf("%s",s);
FOR(j,0,m-1)
if(s[j]=='#')
{
e[i].v.push_back(point{k,j});
}
}
double ans = 0;
FOR(j,0,e[i].v.size()-1){
double tot = maxa*10;
FOR(k,0,e[0].v.size()-1)
if(dis(e[0].v[k],e[i].v[j])<tot)
{
tot = dis(e[0].v[k],e[i].v[j]);
}
if(tot>ans)
ans = tot;
}
e[i].d = ans;
}
sort(e+1,e+l+1,comp);
FOR(i,1,l)
{
cout<<e[i].name<<endl;
cout<<fixed<<setprecision(5)<<e[i].d<<endl;
}
return 0;
} -
2021-12-23 20:25:27@
我!!!
- 1