Think:
不得不说 水出 这题是 特别有成就感~~~~~~~ 但是 怼了 好久 !!!!!!!!前面的英语是 废话!!! 就是让我们数 凸四边形的个数TAT , 直接枚举暴力 过~~~~~
主要想法:
因为 不是 凸四边形 就是 凹四边形, 所以 就用 凹四边形的面积来算个数。
在凹四边形中 必定 有一点在内部, 所以 就可以 得出面积关系 eg Sabc = Sabd + Sacd + Sbcd; 只要不满足 这个关系的 就是 凸四边形~~~~~~~~
K函数的目的是 算出面积, flag函数的目的是判断。。。。
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-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
#include<iostream>
#include<cstdio>
using namespace std;
struct node
{
int x;
int y;
}a[10086];
//a b c d ====> abc abd acd bcd
double K(struct node A, struct node B, struct node C)
{
double ans;
ans = (1.0 * (B.x - A.x) * 1.0 * (C.y - A.y) - 1.0 * (C.x - A.x) * 1.0 * (B.y - A.y))/ 2.0;
if (ans < 0) ans = -ans;
return ans;
}
bool flag(struct node A, struct node B, struct node C, struct node D)
{
double ans;
ans = K(A, B, C) - K(A, B, D) - K(A, C, D) - K(B, C, D);
if (ans < 0) ans = -ans;
if (ans <= 1e-6)
return false;
else
return true;
}
int main()
{
int kase = 0;
int i, j, k, t;
int T;
int cnt;
cin >> T;
while(T --)
{
int n;
cin >> n;
kase ++;
cnt = 0;
for (i = 0; i <= n - 1; i ++)
cin >> a[i].x >> a[i].y;
for (i = 0; i <= n - 1; i ++)
for (j = i + 1; j <= n - 1; j ++)
for (k = j + 1; k <= n - 1; k ++)
for (t = k + 1; t <= n - 1; t ++)
{
if (((flag(a[i], a[j],a[k],a[t])&& flag(a[i], a[t], a[k],a[j])) &&(flag(a[i], a[j], a[t], a[k])&& flag(a[t], a[j], a[k],a[i]))))
cnt ++;
}
printf("Case %d: %d\n", kase, cnt);
}
}