Problem 2148 Moon Game
Accept: 386 Submit: 1080
Time Limit: 1000 mSec Memory Limit : 32768 KB
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
http://acm.fzu.edu.cn/problem.php?pid=2148
//题意是求给定点最多能构成多少个凸四边形。
如何判断凸四边形: 如果4个点中存在某个点D,Sabd + Sacd + Sbcd = Sabc,则说明是凹四边形。因为n很小,所以直接暴力枚举每四个点是否构成凸四边形。
#include<cstdio> #include<cmath> using namespace std; const double eps=1e-8; struct point { int x,y; }p[35]; double area(point a,point b,point c) //三角形面积公式 { return fabs(1.0*(a.x*b.y+b.x*c.y+c.x*a.y-a.x*c.y-b.x*a.y-c.x*b.y))/2; } bool check(point a,point b,point c,point d) //判断是否是凸边形,注意 这里假设a为四边形的内点,要跟下面四重循环对应 { if(fabs(area(b,c,d)-area(a,b,c)-area(a,b,d)-area(a,c,d))<eps) //面积相等 return 0; return 1; } int main() { int t,i,j,k,n,a,b,ans; scanf("%d",&t); for(k=1;k<=t;k++) { ans=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); if(n<4) printf("Case %d: %d\n",k,ans); else { for(i=0;i<n;i++) for(j=i+1;j<n;j++) for(a=j+1;a<n;a++) for(b=a+1;b<n;b++) if(check(p[i],p[j],p[a],p[b])&&check(p[j],p[i],p[a],p[b])&&check(p[a],p[i],p[j],p[b])&&check(p[b],p[i],p[j],p[a])) ans++; printf("Case %d: %d\n",k,ans); } } return 0;
}
FZU_ Problem 2148 Moon Game