fzu 2110 star 结构体

来源:互联网 发布:js向上取整 编辑:程序博客网 时间:2024/05/19 20:57


Description

Overpower 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.

Output

For each test case, output an integer indicating the total number of different acute triangles.

Sample Input

1
3
0 0
10 0
5 1000

Sample Output

1


问题描述:

给你n个坐标,看能构成锐角三角形的最大数目

代码:

#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;struct Node{    int x,y;};bool ischeck(Node a,Node b,Node c){    bool flag=false;    double s[3]={0};    s[0]=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);///ab    s[1]=(a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y);///ac    s[2]=(b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y);///bc    sort(s,s+3);    if(s[0]+s[1]>s[2])        if(s[0]*s[0]+s[1]*s[1]>s[2]*s[2])            flag=true;    return flag;}int main(){    int t,n,cnt;    scanf("%d",&t);    while(t--)    {        Node node[101];        cnt=0;        scanf("%d",&n);        for(int i=0; i<n; i++)            scanf("%d%d",&node[i].x,&node[i].y);        for(int i=0; i<n-2; i++)            for(int j=i+1; j<n-1; j++)                for(int k=j+1; k<n; k++)                    if(ischeck(node [i],node [j],node [k]))                        cnt++;        cout<<cnt<<endl;    }    return 0;}

微笑

0 0