Fzu problem 2148 moon game (judgement convex quadrilateral)

Source: Internet
Author: User

Question Link

Question: Give You N points to determine the number of convex quadrants that can be formed.

Idea: If a concave quadrilateral is formed, it indicates that a point is inside the triangle connected by the other three points. In this way, you only need to determine the area of the three triangles connected to each of the other three points and the area of the triangle composed of the other three points.

I forgot to add FABS in the middle, and I still made a mistake several times.

 1 //FZU2148 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <cmath> 6 #define eps  1e-9 7 #define zero(x) (((x)>0? (x) : (-x)) < eps ) 8  9 using namespace std ;10 11 struct point{double x;double y ;}p[32];12 struct Line{point a;point b;};13 14 double area(point a,point b,point c)15 {16     return a.x * b.y + c.x * a.y + b.x * c.y - c.x * b.y - a.x * c.y - b.x * a.y ;17 }18 bool judge(point a,point b,point c,point d)19 {20     double sum = fabs(area(a,b,c))+fabs(area(a,b,d))+fabs(area(a,c,d)) ;21     double sun = fabs(area(b,c,d)) ;22     if(fabs(sum-sun) <eps) return true ;23     return false ;24 }25 bool solve(point a,point b,point c,point d)26 {27     if(judge(a,b,c,d) || judge(b,a,c,d) || judge(c,b,a,d) || judge(d,b,c,a)) return false ;28     return true ;29 }30 int main()31 {32     int T,casee = 1, n;33     scanf("%d",&T) ;34     while(T--)35     {36         scanf("%d",&n) ;37         for(int i = 0 ; i < n ; i++)38             scanf("%lf %lf",&p[i].x,&p[i].y) ;39         int ans = 0 ;40         for(int i = 0 ; i < n ; i++)41         {42             for(int j = i+1 ; j < n ; j++)43             {44                 for(int k = j + 1 ; k < n ; k++)45                 {46                     for(int h = k+1 ; h < n ; h++)47                     {48                         if(solve(p[i],p[j],p[k],p[h])) ans ++ ;49                     }50                 }51             }52         }53         printf("Case %d: %d\n",casee ++ ,ans) ;54     }55     return 0 ;56 }
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.