UVA152-一堆树

我的天,这个题我Runtime error 10遍,我当时就崩溃了,
10403042 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:51:02
10403024 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:46:35
10403017 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:43:57
10402992 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:36:05
10402981 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:30:40
10402951 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:20:55
10402944 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:17:41
10402938 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:16:07
10402928 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:13:00
10402919 152 Tree's a Crowd Runtime error C++ 0.000 2012-07-29 03:08:58
奶奶的,这得罚时多少啊,最后,我还是回光返照似的AC掉了,
究其原因,还是自己的循环没学好啊。
h[]的长度共为10;
当min>10的时候,
h[]就越界了。
这就是runtime error的原因
忘了判断min与10的大小关系了
!!!!


#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
int main ()
{
    int his[10];
    double a[5050], b[5050], c[5050];
    memset(his,0,sizeof(int)*10);
    int k = 0;
    while(1)
    {   cin>>a[k]>>b[k]>>c[k];
        if(!a[k]&&!b[k]&&!c[k])break;
        k++;
    }
    double min ;
    for(int i = 0; i < k; i++)
    {
        min = 11;
        for(int j = 0;j < k;j++)
        {
            if(i == j)continue;
            int dis = sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j])+(c[i]-c[j])*(c[i]-c[j]));
            min = ((min - dis <0.0001) ? min : dis);

        }
        if(10-min<0.0001)continue;
        int h = int(min);
        //cout<<min<<"->"<<h<<endl;
        his[h]++;
    }
    for(int i= 0; i < 10; i++)
        cout<<setw(4)<<his[i];
    cout<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值