FZU 2110 Star 数学

Star

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

FZU 2110

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

套一个锐角三角形的性质就可以了 两边平方和大于第三边的平方和

开始用第一种方法来做 比较耗时 后来看了高端玩家是怎么循环的 第二种方法的耗时大大的降低way1
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int,int> PII;

const int MX = 100 + 5;

struct Point{
    double x, y;
}P[MX];

bool check(int i, int j, int k){
    if(i == j || i == k || j == k)  return false;
    double len1 = (P[i].x - P[j].x)*(P[i].x - P[j].x) + (P[i].y - P[j].y)*(P[i].y - P[j].y);
    double len2 = (P[i].x - P[k].x)*(P[i].x - P[k].x) + (P[i].y - P[k].y)*(P[i].y - P[k].y);
    double len3 = (P[j].x - P[k].x)*(P[j].x - P[k].x) + (P[j].y - P[k].y)*(P[j].y - P[k].y);
    len1 = sqrt(len1);
    len2 = sqrt(len2);
    len3 = sqrt(len3);
    if(len1 * len1 + len2 * len2 > len3 * len3)
        if(len1 * len1 + len3 * len3 > len2 * len2)
             if(len3 * len3 + len2 * len2 > len1 * len1)
                  return true;

    return false;
}
int main(){
    //FIN
    int t;
    while (~scanf ("%d", &t)){
        while (t--){
            int n;
            scanf ("%d", &n);
            for (int i = 0; i < n; i ++) scanf ("%lf%lf", &P[i].x, &P[i].y);
            int cnt = 0;
            for (int i = 0; i < n; i ++){
                for(int j = 0; j < n ; j ++){
                    for(int k = 0; k < n; k ++){
                        if(check(i, j, k))  cnt ++;
                    }
                }
            }
            printf ("%d\n",cnt/6);
        }
    }
    return 0;
}

way2

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int,int> PII;

const int MX = 100 + 5;

struct Point{
    double x, y;
}P[MX];

bool check(int i, int j, int k){
    double len1 = (P[i].x - P[j].x)*(P[i].x - P[j].x) + (P[i].y - P[j].y)*(P[i].y - P[j].y);
    double len2 = (P[i].x - P[k].x)*(P[i].x - P[k].x) + (P[i].y - P[k].y)*(P[i].y - P[k].y);
    double len3 = (P[j].x - P[k].x)*(P[j].x - P[k].x) + (P[j].y - P[k].y)*(P[j].y - P[k].y);
    len1 = sqrt(len1);
    len2 = sqrt(len2);
    len3 = sqrt(len3);
    if(len1 * len1 + len2 * len2 > len3 * len3)
        if(len1 * len1 + len3 * len3 > len2 * len2)
             if(len3 * len3 + len2 * len2 > len1 * len1)
                  return true;

    return false;
}
int main(){
    //FIN
    int t;
    while (~scanf ("%d", &t)){
        while (t--){
            int n;
            scanf ("%d", &n);
            for (int i = 0; i < n; i ++) scanf ("%lf%lf", &P[i].x, &P[i].y);
            int cnt = 0;
            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(check(i, j, k))  cnt ++;
                    }
                }
            }
            printf ("%d\n",cnt);
        }
    }
    return 0;
}

  

时间: 2024-10-07 09:49:49

FZU 2110 Star 数学的相关文章

ACM: FZU 2110 Star - 数学几何 - 水题

FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Practice 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.

FZU OJ 2110 Star (计算几何)

Problem 2110 Star Accept: 585    Submit: 1731 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem 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 s

FZU Problem 2110 Star (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2110 Problem 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

FZU 2147(数学,规律)

Problem 2147 A-B Game Accept: 1202    Submit: 2853 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game by two integers A and B. First Fat brother write an integer A on

&quot;高教社杯&quot;第三届福建省大学生程序设计竞赛

 A.Problem 2102 Solve equation Accept: 1032    Submit: 2471 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-

数学 FZU 2074 Number of methods

题目传送门 1 /* 2 数学:假设取了第i个,有C(n-1)(i-1)种取法 3 则ans = sum (C(n-1)(i-1)) (1<i<=n) 即2^(n-1) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 1

FZU Problem 2102 Solve equation (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2102 Problem Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in

FZU Problem 2104 Floor problem (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2104 Problem Description In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2. You are given 3 posit

FZU Problem 2111 Min Number (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2111 Problem Description Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, her