您的位置:首页 > 其它

FZU 2148 Moon Game

2016-04-19 21:52 369 查看
题意:给定n个点,问选4个点能组成凸四边形的个数

思路:凸包模板上

#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#define N 100000
#define LL long long
#define U unsigned
using namespace std;
struct Point
{
int x,y;
Point(int a,int b)
{
x=a;y=b;
}
Point() { }
bool operator<(const Point &a)const
{
return x<a.x||(x==a.x&&y<a.y);
}
Point operator -(const Point &a) const
{
return Point(x-a.x,y-a.y);
}
};
int Cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
int ConvexHull(Point*p,int n,Point*ch)
{
sort(p,p+n);
int m=0;
for(int i=0;i<n;i++)
{
while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;i--)
{
while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;
ch[m++]=p[i];
}
if(n>1) m--;
return m;
}
Point a[40],b[10],c[10];
int cas=1,T;
int n;
int main()
{
//freopen("1.in","w",stdout);
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d%d",&a[i].x,&a[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 l=k+1;l<n;l++)
{
b[0]=a[i];b[1]=a[j];b[2]=a[k];b[3]=a[l];
if(ConvexHull(b,4,c)==4) ans++;
}
}
}
}
printf("Case %d: %d\n",cas++,ans);
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}


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

240 0100 00 100100 10040 0100 00 10010 10

Sample Output

Case 1: 1Case 2: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: