FZU Problem 2148 Moon Game (判断凸四边形)

题目链接

题意 : 给你n个点,判断能形成多少个凸四边形。

思路 :如果形成凹四边形的话,说明一个点在另外三个点连成的三角形内部,这样,只要判断这个内部的点与另外三个点中每两个点相连组成的三个三角形的面积和要与另外三个点组成的三角形面积相同。

中途忘了加fabs还错了好几次

 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 }

FZU Problem 2148 Moon Game (判断凸四边形)

时间: 2024-10-18 11:08:21

FZU Problem 2148 Moon Game (判断凸四边形)的相关文章

FZU 2148 Moon Game 判断凸边形

点击打开链接 Problem 2148 Moon Game Accept: 512    Submit: 1419 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 k

FZU_ Problem 2148 Moon Game

 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

FZOJ Problem 2148 Moon Game

                                                                                              Problem 2148 Moon Game Problem Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consid

FZU 2148 Moon Game (枚举+几何)

 Problem 2148 Moon Game Accept: 403    Submit: 1126Time 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

FZU 2148 moon game (计算几何判断凸包)

Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status 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-dime

【暴力+排除法】FZU 2148 Moon Game

比赛地址:点击打开链接 比赛做粗的4个题几乎都是水,感觉弱的水爆炸了. 这个题最初的思路是枚举找出四个点,做凸多边形的模板判断.C(30,4). 结果答案不对..后来发现模板上是要求点对的顺序是逆时针或顺时针输入. 于是用时钟排序的函数排序后判断: bool cmp(point p1, point p2) { return atan2(p1.y, p1.x) < atan2(p2.y, p2.x); } 结果tle了两遍.. 最后发现其实不用模板上这样.可以用判断是不是凹多边形的办法,反正总体是

ACM: FZU 2148 Moon Game - 海伦公式

FZU 2148  Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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-dimensio

FZU 2148 Moon Game --判凹包

题意:给一些点,问这些点能够构成多少个凸四边形 做法: 1.直接判凸包 2.逆向思维,判凹包,不是凹包就是凸包了 怎样的四边形才是凹四边形呢?凹四边形总有一点在三个顶点的内部,假如顶点为A,B,C,D,则构成四个三角形:ABC,ACD,ABD,BCD,假如某一个三角形(最外的三个顶点)的面积等于另三个三角形面积之和,则是凹四边形. 然后做四个for循环,枚举即可,因为N最多才30. 代码: #include <iostream> #include <cstdio> #include

hdu 4975 A simple Gaussian elimination problem.(网络流,判断矩阵是否存在)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One day, he drew a table with several rows and columns, randomly wrote numbers on each elements of the table. Then he counted the sum of each row and col