您的位置:首页 > 其它

FZU - 2148 Moon Game

2014-10-26 23:17 337 查看
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>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

struct node
{
int x, y;
}p[35];
int  Dir(node p1,node p2,node p0) {
//判断线段p0p2相对于线段p0p1的位置
//向量p0p1叉乘向量p0p2,转化为行列式进行计算
//结果若大于0,则p0p2沿顺时钟方向旋转可得到与p0p1同方向的向量
//结果若小于0,则p0p2沿逆时钟方向旋转可得到与p0p1同方向的向量
//结果若等于0,则p0p2与p0p1共线
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}

int  inter(node a, node b, node c, node d)
{
if(
min(a.x, b.x) > max(c.x, d.x) ||
min(a.y, b.y) > max(c.y, d.y) ||
min(c.x, d.x) > max(a.x, b.x) ||
min(c.y, d.y) > max(a.y, b.y)
)
return 0;
long long x1, x2, x3, x4;
x1=Dir(d,a,c);
x2=Dir(d,b,c);
x3=Dir(b,c,a);
x4=Dir(b,d,a);
if (x1 * x2 < 0 && x3 * x4 < 0)
return 1;
}

int fun(node a1,node a2,node a3,node a4) //对角线的情况
{
if (inter(a1, a2, a3, a4)) return 1;
if (inter(a1, a3, a2, a4)) return 1;
if (inter(a1, a4, a2, a3)) return 1;
return 0;
}

int main()
{
int T;
scanf ("%d", &T);
for (int i = 1; i <= T; ++ i)
{
int n;
scanf ("%d", &n);
for (int i = 0; i < n; ++i)
{
scanf ("%d%d", &p[i].x, &p[i].y);
}
int ans = 0;
for (int i = 0; i < n; ++i)
{
for (int j = i + 1; j < n; ++j)
{
for (int k = j + 1; k < n; ++k)
{

for (int h = k + 1; h < n; ++h)
{

if (fun(p[i],p[j],p[k],p[h])) ans++;
}
}
}
}
printf ("Case %d: %d\n", i, ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  FZU - 2148 Moon Game