FZU-2148-Moon Game,,几何计算~~

来源:互联网 发布:淘宝收货地址写什么 编辑:程序博客网 时间:2024/06/05 10:17

Problem 2148 Moon Game

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


     题意也不难懂,就是找有多少个凸四边形,而且题目不会有三点共线的情况,开始做的时候想的是用角度判断的方法,,快结束了才知道思路是错的,记得在小白书(算法入门经典)85业看过有向三角形面积计算,目的就是判断一个点是否在三角形内,,这个题就可以用这种思路,也就是说如果所选四个点中有一个点在其他三个点所围成的三角形内部,他就是凹三角形,反之~~~~

      有了正确思路,代码就不成问题了吧;

             

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int N=50;struct node{    int x,y;} a[N];int fun(int a){    return a>0?a:-a;//因为是有向面积,可正可负;}int mj(int x1,int y1,int x2,int y2,int x3,int y3){    return fun(x1*y2+x3*y1+x2*y3-x3*y2-x1*y3-x2*y1);//有向面积计算公式;}int main(){    int t,n;    scanf("%d",&t);    int t1=t;    while(t--)    {        int sum=0;        scanf("%d",&n);        for(int i=1; i<=n; i++)            scanf("%d%d",&a[i].x,&a[i].y);        for(int i=1; i<=n-3; i++)            for(int j=i+1; j<=n-2; j++)                for(int k=j+1; k<=n-1; k++)                    for(int l=k+1; l<=n; l++)                    {                        if(mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y)==mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)+                                mj(a[i].x,a[i].y,a[l].x,a[l].y,a[k].x,a[k].y)+mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y))                            continue;//点l在中间的情况;                        if(mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)==mj(a[i].x,a[i].y,a[k].x,a[k].y,a[l].x,a[l].y)+                                mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y)+mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y))                            continue;//点k在中间的情况;                        if(mj(a[i].x,a[i].y,a[k].x,a[k].y,a[l].x,a[l].y)==mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)+                                mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y)+mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y))                            continue;//点j在中间的情况;                        if(mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y)==mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)+                                mj(a[i].x,a[i].y,a[l].x,a[l].y,a[k].x,a[k].y)+mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y))                            continue;//点i在中间的情况;                            sum++;                    }        printf("Case %d: ",t1-t);        printf("%d\n",sum);    }    return 0;}

0 0
原创粉丝点击