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
4
0 0
100 0
0 100
100 100
4
0 0
100 0
0 100
10 10
Sample Output
Case 2: 0
题意:给定我们四个点的坐标,求这四个点能围城的凸四边形的个数
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cmath>
using namespace std;
struct node{
int x,y;
}num[35];
#define exp 1e-8//求面积之差的精度
double x(node a,node b,node c)
{
return fabs(1.0*(a.x*b.y-a.y*b.x+b.x*c.y-b.y*c.x+c.x*a.y-c.y*a.x))/2.0;//求三角形面积的叉积公式
}
int check(node a,node b,node c,node d)
{
if(fabs(x(b,c,d)-x(a,b,c)-x(a,b,d)-x(a,c,d))<exp)//假如某一个三角形(最外的三个顶点)的面积等于另三个三角形面积之和,则是凹四边形。
//假设以a为凹点,那么bcd组成的面积最大,如果四个三角形的面积之差小于exp,那么就是凹四边形,
{
return 0;
}
return 1;
}
int main()
{
int t,n,i,j,k,r,m=1,cnt;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>num[i].x>>num[i].y;
}
cnt=0;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
for(k=j+1;k<n;k++)
{
for(r=k+1;r<n;r++)
{
if(check(num[i],num[j],num[k],num[r])&&check(num[j],num[i],num[k],num[r])&&check(num[k],num[i],num[j],num[r])&&check(num[r],num[i],num[j],num[k]))
{
cnt++;//如果以任意一点为凸点,都满足条件,那么肯定是凸四边形
}
}
}
}
}
cout<<"Case "<<m++<<": "<<cnt<<endl;
}
return 0;
}