ACM learning process-fzu2148 moon game (computational geometry)

Source: Internet
Author: User

Moon game

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-dimen=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


This is a question for calculating the number of convex quadrants. You only need to enumerate all the four sides to judge the number.
It is used to enumerate the diagonal lines. In one case, the intersection of two diagonal lines is a convex quadrilateral. The intersection of line segments is used for determination.


Code:
 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cmath> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <queue>10 #include <string>11 #include <vector>12 #define inf 0x3fffffff13 14 using namespace std;15 16 struct point17 {18     int x, y;19 }p[35];20 21 point a1, a2, a3, a4;22 23 bool inter(point a, point b, point c, point d)24 {25     if(26        min(a.x, b.x) > max(c.x, d.x) ||27        min(a.y, b.y) > max(c.y, d.y) ||28        min(c.x, d.x) > max(a.x, b.x) ||29        min(c.y, d.y) > max(a.y, b.y)30        )31         return 0;32     long long x1, x2, x3, x4;33     x1 = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);34     x2 = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);35     x3 = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);36     x4 = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);37     return x1 * x2 < 0 && x3 * x4 < 0;38 }39 40 bool fun()41 {42     if (inter(a1, a2, a3, a4)) return 1;43     if (inter(a1, a3, a2, a4)) return 1;44     if (inter(a1, a4, a2, a3)) return 1;45     return 0;46 }47 48 int main()49 {50     //freopen ("test.txt", "r", stdin);51     int T;52     scanf ("%d", &T);53     for (int times = 1; times <= T; ++times)54     {55         int n;56         scanf ("%d", &n);57         for (int i = 0; i < n; ++i)58         {59             scanf ("%d%d", &p[i].x, &p[i].y);60         }61         int ans = 0;62         for (int i = 0; i < n; ++i)63         {64             a1 = p[i];65             for (int j = i + 1; j < n; ++j)66             {67                 a2 = p[j];68                 for (int k = j + 1; k < n; ++k)69                 {70                     a3 = p[k];71                     for (int h = k + 1; h < n; ++h)72                     {73                         a4 = p[h];74                         if (fun()) ans++;75                     }76                 }77             }78         }79         printf ("Case %d: %d\n", times, ans);80     }81     return 0;82 }
View code

 

ACM learning process-fzu2148 moon game (computational geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.