UVA - 152 Tree's a Crowd

来源:互联网 发布:mac定制双用粉底液53c1 编辑:程序博客网 时间:2024/06/05 11:42

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18650

开始题意一直没看懂,百度了才知道是什么意思!

题目大意:给你一组三维空间中的点,每个点到其它点都有个距离,其中有个最小距离,如果这个最小距离小于10,就将对应的距离值的点个数加1,最后输出距离值为0,1,2,3,4,5,6,7,8,9的点的个数。

再看题目一想发现还是自己理解错了。题目很简单!

#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct node{    int x,y,z;}p[5010];int solve(node a,node b){    return (int)sqrt(1.0*(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));}int main(){    //freopen("a.txt","r",stdin);    int n=1,i,j,f[11];    while(~scanf("%d %d %d",&p[n].x,&p[n].y,&p[n].z))    {        if(p[n].x==0&&p[n].y==0&&p[n].z==0) break;       // printf("%d %d %d\n",p[n].x,p[n].y,p[n].z);        n++;    }    //printf("%d\n",n);    memset(f,0,sizeof(f));    for(i=1;i<n;i++)    {        int m=260;        for(j=1;j<n;j++)        {            if(i!=j)            {                int ans=solve(p[i],p[j]);                if(ans<m) m=ans;            }        }        if(m<10) f[m]++;    }    for(i=0;i<10;i++)        printf("%4d",f[i]);    printf("\n");    return 0;}


0 0
原创粉丝点击