FZU 2148 Moon Game(计算几何)

    xiaoxiao2024-07-24  16

    I - Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  Status  Practice  FZU 2148

    Description

    Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N starts in the sky which we can just consider each as a point. After he draws these stars, he starts to sing the famous song “The Moon Represents My Heart” to Maze.

    You ask me how deeply I love you,

    How much I love you?

    My heart is true,

    My love is true,

    The moon represents my heart.

    But as Fat brother is a little bit stay-adorable(呆萌), he just consider that the moon is a special kind of convex quadrilateral and starts to count the number of different convex quadrilateral in the sky. As this number is quiet large, he asks for your help.

    Input

    The first line of the date is an integer T, which is the number of the text cases.

    Then T cases follow, each case contains an integer N describe the number of the points.

    Then N lines follow, Each line contains two integers describe the coordinate of the point, you can assume that no two points lie in a same coordinate and no three points lie in a same line. The coordinate of the point is in the range[-10086,10086].

    1 <= T <=100, 1 <= N <= 30

    Output

    For each case, output the case number first, and then output the number of different convex quadrilateral in the sky. Two convex quadrilaterals are considered different if they lie in the different position in the sky.

    Sample Input

    2 4 0 0 100 0 0 100 100 100 4 0 0 100 0 0 100 10 10

    Sample Output

    Case 1: 1 Case 2: 0

    由于提供的N最大只有30,所以我们完全可以直接暴力,接着就是判断四个点是不是凸四边形,我们只要判断第四个点是否在前三个点构成的三角形中就可以了,如果在则不是凸四边形,否则是凸四边形

    这里用到了一个函数area专门求解一个三角形的有向面积的

    #include <queue> #include <cmath> #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> using namespace std; //#pragma comment(linker, "/STACK:1024000000,1024000000") #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define fst first #define snd second typedef __int64 LL; typedef pair<int, int> PII; const int MAXN = 30 + 5; int T, n; int X[MAXN], Y[MAXN]; int area (int x0, int y0, int x1, int y1, int x2, int y2) { return abs (x0 * y1 + x2 * y0 + x1 * y2 - x2 * y1 - x0 * y2 - x1 * y0); } int A[MAXN]; int main() { #ifndef ONLINE_JUDGE FIN; // FOUT; #endif // ONLINE_JUDGE int cas = 0; scanf ("%d", &T); while (T --) { scanf ("%d", &n); for (int i = 0; i < n; i ++) { scanf ("%d%d", &X[i], &Y[i]); } int res = 0; for (int i = 0; i < n; i ++) { for (int j = 0; j < i; j ++) { for (int k = 0; k < j; k ++) { for (int h = 0; h < k; h ++) { A[0] = area (X[i], Y[i], X[j], Y[j], X[k], Y[k]); A[1] = area (X[h], Y[h], X[i], Y[i], X[j], Y[j]); A[2] = area (X[h], Y[h], X[j], Y[j], X[k], Y[k]); A[3] = area (X[h], Y[h], X[k], Y[k], X[i], Y[i]); sort(A, A + 4); if (A[3] != A[0] + A[1] + A[2]) { res ++; } } } } } printf ("Case %d: %d\n", ++cas, res);; } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1290995.html
    最新回复(0)