The meaning of this question is to give you n points, you can judge that these n points can form several convex quadrilateral. The core of this problem is the composition condition of convex quadrilateral. If three points, any three points constitute a triangle, and the fourth point is outside the triangle, then it is a convex quadrilateral.
If a point P is inside the triangle, then Sabc = Sabp + Sbcp + Sacp;
This problem is better not to use Helen's formula to calculate the area, because there will be accuracy problems, it is not easy to judge the equality, so a new method of cross-product is given.
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
struct node
{
int x;
int y;
}p[35];
int square(node a, node b, node c)
{
return abs((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y));
}
//By cross-multiplying, the area of the triangle is twice as large as that of the triangle.
bool judge(node a, node b, node c, node d)
{
int abc = square(a, b, c);
int abd = square(d, a, b);
int acd = square(d, a, c);
int bcd = square(d, b, c);
if(abd + acd + bcd == abc)
return false;
return true;
}
int main()
{
int t, n, i, cas = 1;
scanf("%d", &t);
while(t--)
{
int cnt = 0;
scanf("%d", &n);
for(i = 0; i < n; i++)
scanf("%d %d", &p[i].x, &p[i].y);
for(i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
for(int k = j + 1; k < n; k++)
{
for(int l = k + 1; l < n; l++)
{
if(judge(p[i], p[j], p[k], p[l]) && judge(p[i], p[j], p[l], p[k]) && judge(p[i], p[l], p[k], p[j]) && judge(p[l], p[j], p[k], p[i]))
//Four judgements should be made here, and attention should be paid to the fact that the order is not arbitrarily exchanged.
cnt++;
}
}
}
}
printf("Case %d: %d\n", cas++, cnt);
}
return 0;
}