zoukankan      html  css  js  c++  java
  • FZU 2148 Moon Game (枚举+几何)

     Problem 2148 Moon Game

    Accept: 403    Submit: 1126
    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

    题目的意思就是说从所给的点中判断能够成几个凸四边形。

    由于所给的n很小,可以枚举所有的情况然后判断是否构成凸四边形。直接去判断是不是凸四边形不好去判断,所以就判断凹四边形的数量然后用组合的数量去减。

    判断凹四边形的方法就是 Sabc=Sabd+Sbcd+Sadc    (Sabc为面积最大的三角形)

    这里说一个三角形面积计算公式吧,当时我用海伦就超时了= =

    平面直角坐标系内,A(a,b),B(c,d),C(e,f)构成之三角形面积为

     。 A,B,C三点最好按逆时针顺序从右上角开始取,因为这样取得出的结果一般都为正值,如果不按这个规则取,可能会得到负值,但只要取绝对值就可以了,不会影响三角形面积的大小。

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<cstring>
     4 #include<stdlib.h>
     5 #include<algorithm>
     6 using namespace std;
     7 struct node
     8 {
     9     double x,y;
    10 }num[35];
    11 
    12 double area(int a,int b,int c)//求三角形面积
    13 {
    14     return num[a].x * num[b].y + num[c].x * num[a].y + num[b].x * num[c].y - num[c].x * num[b].y - num[a].x * num[c].y - num[b].x * num[a].y;
    15 }
    16 
    17 int solve(int i,int j,int k,int l)
    18 {
    19     double s1,s2,s3,s4,max_area;
    20     s1=fabs(area(i,j,k));
    21     s2=fabs(area(i,j,l));
    22     s3=fabs(area(i,k,l));
    23     s4=fabs(area(j,k,l));
    24     max_area=max(s1,max(s2,max(s3,s4)));
    25     if(fabs(max_area*2-fabs(s1+s2+s3+s4))<1e-9)
    26         return 1;
    27     return 0;
    28 }
    29 
    30 int main()
    31 {
    32     //freopen("in.txt","r",stdin);
    33     int kase,n,cnt=0;
    34     scanf("%d",&kase);
    35     while(kase--)
    36     {
    37 
    38         scanf("%d",&n);
    39         if(n<4)
    40         {
    41             printf("0
    ");
    42             continue;
    43         }
    44 
    45         int Cn4=n*(n-1)*(n-2)*(n-3)/24;
    46         //printf("cn4=%d
    ",Cn4);
    47         for(int i=0;i<n;i++)
    48             scanf("%lf %lf",&num[i].x,&num[i].y);
    49 
    50         int sum=0;
    51         for(int i=0;i<n;i++)
    52         {
    53             for(int j=i+1;j<n;j++)
    54             {
    55                 for(int k=j+1;k<n;k++)
    56                 {
    57                     for(int l=k+1;l<n;l++)
    58                     {
    59                         if(solve(i,j,k,l))
    60                             sum++;
    61                     }
    62                 }
    63             }
    64         }
    65         //printf("sum=%d
    ",sum);
    66         int ans=Cn4-sum;
    67         printf("Case %d: %d
    ",++cnt,ans);
    68     }
    69     return 0;
    70 }
    View Code
  • 相关阅读:
    信用风险评分卡研究-第7章笔记
    信用风险评分卡研究-第6章笔记
    信用风险评分卡研究-第5章
    CSS3新特性
    H5相关知识点整理
    css3实现立体魔方效果
    后台管理系统基本布局
    react路由初探(2)
    react路由初探(1)
    将一个数组转化为需要的格式,来自react官网的商品列表示例
  • 原文地址:https://www.cnblogs.com/clliff/p/3932509.html
Copyright © 2011-2022 走看看