UVA152-Tree’s a Crowd

來源:互聯網
上載者:User

題意:求各棵樹到其他樹的最短距離,然後記錄下來,距離只有0-9

思路:暴力把。。。直接搜尋,但要記住,最後的距離是向下取整,而不是向上取整,剛開始理解錯誤,用ceil取整距離,WA了好多次,後來才發現,直接用int強制轉化

#include<stdio.h> #include<stdlib.h>#include<math.h> #include<string.h>int dis[11];struct space{double x, y, z;}space[5050];double lenth(double a, double b, double c, double d, double e, double f){double l;return l = sqrt((a - d) * (a - d) + (b - e) * (b - e) + (c - f) * (c - f));}int main(){int cnt = 0, min;double L;memset(dis, 0, sizeof(dis));while (scanf("%lf%lf%lf", &space[cnt].x, &space[cnt].y, &space[cnt].z)){if (!space[cnt].x && !space[cnt].y && !space[cnt].z)break;cnt++;}for(int i = 0; i < cnt; i++){min = 9999999;for(int j = 0; j < cnt; j++){if (i == j)continue;L = lenth(space[i].x, space[i].y, space[i].z, space[j].x, space[j].y, space[j].z);if (L < min)min = L;}if (min <= 9){int k = floor(min);dis[k]++;}}for(int i = 0; i < 10; i++)printf("%4d", dis[i]);printf("\n");return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.