嗜血魂K

导航

152 Tree's a Crowd

//开始理解错题意,以为每两棵都比较,然后统计,结果对于每一棵树,只统计与它距离最近的

//原来double不能读int,那题目的意思应该数据只有int

//结构体果断不怎么熟悉,写以结构体为参数的函数的时候,汗颜

//Conclusion:

struct test{
int test;
};
void test(struct test *a)
{
printf a
->test 或 (*a).test
scanf
&(a->test) 或 &(*a).test
}

以及:runtime error 一般都是数组越界,我遇到的是有数组没开够和访问越界

#include<stdio.h>
#include
<math.h>
typedef
struct tree{
int x,y,z;
}Tree;
int dis(Tree a, Tree b)
{
return (int)(sqrt( (double)((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z)) ) + 5e-6);
}
int tree_scan(Tree *a)
{
scanf(
"%d %d %d", &(a->x), &(*a).y, &(*a).z);
if(a->x || a->y || a->z) return 1;
else return 0;
}
int main()
{
#ifdef LOCAL
freopen(
"152.in", "r", stdin);
#endif
Tree t[
6000];
int n = 0, i, j, count[10] = {0}, min;
for(; tree_scan(&t[n]); n++);//实际n-1棵
for(i = 0; i < n; i++)
{
for(j = 0, min = 500; j < n; j++)
if(j != i && min > dis(t[i], t[j])) min = dis(t[i], t[j]);
if(min < 10)count[min]++;
}
for(i = 0; i < 10; i++) printf("%4d", count[i]);
printf(
"\n");
return 0;
}

  

posted on 2011-09-08 18:34  嗜血魂K  阅读(171)  评论(0)    收藏  举报