FZU OJ 2110 Star (計算幾何),fzuoj

來源:互聯網
上載者:User

FZU OJ 2110 Star (計算幾何),fzuoj
Problem 2110 StarAccept: 585    Submit: 1731
Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem DescriptionOverpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem. Input

The first line of the input contains an integer T (T≤10), indicating the number of test cases.

For each test case:

The first line contains one integer n (1≤n≤100), the number of stars.

The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.

 OutputFor each test case, output an integer indicating the total number of different acute triangles. Sample Input130 010 05 1000 Sample Output1 Source題意:給你一些點,計算這些點能組成多少個銳角三角形。銳角三角形計算公式:a*a+b*b>c*c (兩邊之間的距離大於第三邊)
#include <iostream>#include <cstring>#include <algorithm>using namespace std;typedef struct Point{    double x,y;}Point;Point point[160];int main(){    int ans, t, i, j, k, n;    double a,b,c;    cin >> t;    while (t--)    {        cin >> n;        for (i=0; i<n; i++)        {            cin >> point[i].x >> point[i].y;        }        ans = 0;        for (i=0; i<n-2; i++)//利用三重迴圈每次計算三個點之間的關係        {            for (j=i+1; j<n-1; j++)            {                for (k=j+1; k<n; k++)                {                    a = (point[i].x-point[j].x)*(point[i].x-point[j].x) + (point[i].y-point[j].y)*(point[i].y-point[j].y);//計算兩點之間的距離                    b = (point[i].x-point[k].x)*(point[i].x-point[k].x) + (point[i].y-point[k].y)*(point[i].y-point[k].y);                    c = (point[k].x-point[j].x)*(point[k].x-point[j].x) + (point[k].y-point[j].y)*(point[k].y-point[j].y);                    if (a+b>c && a+c>b && c+b>a) //三點都滿足才是銳角三角形                    {                        ans++;                    }                }            }        }        cout << ans << endl;    }    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.