您的位置:首页 > 其它

uva 152 Tree's a Crowd

2011-09-20 22:38 573 查看
题意:给你空间中的几个点,要你找出与当前点距离最小的点(幸好题意数据量不太大。。)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct node
{
double a,b,c;
}tree[5005];
int a[10];
int main()
{
int n=0;
while(scanf("%lf%lf%lf",&tree
.a,&tree
.b,&tree
.c)!=EOF)
{
if(tree
.a==0&&tree
.b==0&&tree
.c==0) break;
n++;
}
for(int i=0;i<n;i++)
{
int imin=1<<29;
for(int j=0;j<n;j++)
{
if(i==j) continue;
int temp=sqrt((tree[i].a-tree[j].a)*(tree[i].a-tree[j].a)+
(tree[i].b-tree[j].b)*(tree[i].b-tree[j].b)+
(tree[i].c-tree[j].c)*(tree[i].c-tree[j].c));
imin=min(imin,temp);
}
a[imin]++;
}
for(int i=0;i<10;i++) printf("%4d",a[i]);
puts("");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: