Fzu 2148 moon game (enumeration + ry)

Source: Internet
Author: User
Problem 2148 moon gameAccept: 403 submit: 1126
Time Limit: 1000 msec memory limit: 32768 kb Problem 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 input240 0100 00 100100 10040 00 0100 10 sample outputcase 1: 1 case 2: 0

 

The question means judging from the given point that a number of convex quadrants can be formed.

Since the given n is very small, we can enumerate all the situations and determine whether a convex quadrilateral is formed. It is difficult to judge whether a convex quadrilateral is used directly. Therefore, the number of concave quadrilateral is determined and then the number of the combination is reduced.

The method for judging the concave quadrilateral is SABC = sabd + SBCD + SADC (SABC is the triangle with the largest area)

Here is a formula for calculating the triangle area. At that time, I used Helen to time out =

 

In the Cartesian coordinate system of the plane, the area of a (a, B), B (c, d), C (e, f) triangle is

. The values of A, B, and C are preferably obtained from the upper right corner in a counterclockwise order, because the result is usually positive. If you do not follow this rule, a negative value may be obtained, however, the absolute value does not affect the area of the triangle.

 

1 # include <cstdio> 2 # include <cmath> 3 # include <cstring> 4 # include <stdlib. h> 5 # include <algorithm> 6 using namespace STD; 7 struct node 8 {9 Double X, Y; 10} num [35]; 11 12 double area (int, int B, int c) // calculates the Triangle Area 13 {14 return num [A]. x * num [B]. Y + num [C]. x * num [A]. Y + num [B]. x * num [C]. y-num [C]. x * num [B]. y-num [A]. x * num [C]. y-num [B]. x * num [A]. y; 15} 16 17 int solve (int I, Int J, int K, int L) 18 {19 double S1, S2, S3, S4, max_area; 20 S1 = FABS (area (I, j, k); 21 S2 = FABS (area (I, j, L); 22 S3 = FABS (area (I, k, L); 23 S4 = FABS (area (J, K, L); 24 max_area = max (S1, max (S2, max (S3, s4); 25 if (FABS (max_area * 2-fabs (S1 + S2 + S3 + S4) <1e-9) 26 return 1; 27 return 0; 28} 29 30 int main () 31 {32 // freopen ("in.txt", "r", stdin); 33 int Kase, N, CNT = 0; 34 scanf ("% d", & Kase); 35 while (Kase --) 36 {37 38 scanf ("% d", & N); 39 if (n <4) 40 {41 printf ("0 \ n"); 42 continue; 43} 44 45 int CN4 = N * (n-1) * (n-2) * (n-3)/24; 46 // printf ("CN4 = % d \ n", CN4); 47 for (INT I = 0; I <n; I ++) 48 scanf ("% lf", & num [I]. x, & num [I]. y); 49 50 int sum = 0; 51 for (INT I = 0; I <n; I ++) 52 {53 for (Int J = I + 1; j <n; j ++) 54 {55 for (int K = J + 1; k <n; k ++) 56 {57 for (int l = k + 1; L <n; l ++) 58 {59 If (solve (I, J, K, L) 60 sum ++; 61} 62} 63} 64} 65 // printf ("sum = % d \ n", sum); 66 int ans = Cn4-sum; 67 printf ("case % d: % d \ n ", ++ CNT, ANS); 68} 69 return 0; 70}
View code

 

Fzu 2148 moon game (enumeration + ry)

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.