ACM学习历程—FZU2148 Moon Game(计算几何)

Moon Game

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

这个题目是一道计算凸四边形个数的题目,只需要暴力枚举所有4边形判断即可。
判断的时候就是枚举对角线,只有有一种情况的两条对角线相交即为凸四边形。这里采用线段相交的模板来判断。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <queue>
10 #include <string>
11 #include <vector>
12 #define inf 0x3fffffff
13
14 using namespace std;
15
16 struct point
17 {
18     int x, y;
19 }p[35];
20
21 point a1, a2, a3, a4;
22
23 bool inter(point a, point b, point c, point d)
24 {
25     if(
26        min(a.x, b.x) > max(c.x, d.x) ||
27        min(a.y, b.y) > max(c.y, d.y) ||
28        min(c.x, d.x) > max(a.x, b.x) ||
29        min(c.y, d.y) > max(a.y, b.y)
30        )
31         return 0;
32     long long x1, x2, x3, x4;
33     x1 = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
34     x2 = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
35     x3 = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
36     x4 = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
37     return x1 * x2 < 0 && x3 * x4 < 0;
38 }
39
40 bool fun()
41 {
42     if (inter(a1, a2, a3, a4)) return 1;
43     if (inter(a1, a3, a2, a4)) return 1;
44     if (inter(a1, a4, a2, a3)) return 1;
45     return 0;
46 }
47
48 int main()
49 {
50     //freopen ("test.txt", "r", stdin);
51     int T;
52     scanf ("%d", &T);
53     for (int times = 1; times <= T; ++times)
54     {
55         int n;
56         scanf ("%d", &n);
57         for (int i = 0; i < n; ++i)
58         {
59             scanf ("%d%d", &p[i].x, &p[i].y);
60         }
61         int ans = 0;
62         for (int i = 0; i < n; ++i)
63         {
64             a1 = p[i];
65             for (int j = i + 1; j < n; ++j)
66             {
67                 a2 = p[j];
68                 for (int k = j + 1; k < n; ++k)
69                 {
70                     a3 = p[k];
71                     for (int h = k + 1; h < n; ++h)
72                     {
73                         a4 = p[h];
74                         if (fun()) ans++;
75                     }
76                 }
77             }
78         }
79         printf ("Case %d: %d\n", times, ans);
80     }
81     return 0;
82 }

时间: 2024-10-13 10:36:39

ACM学习历程—FZU2148 Moon Game(计算几何)的相关文章

ACM学习历程—HDU 4726 Kia&#39;s Calculation( 贪心&amp;&amp;计数排序)

DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds 9. For example, when she calculates 4567+5789, she will get 9246, and for 12

ACM学习历程—HDU 5023 A Corrupt Mayor&#39;s Performance Art(广州赛区网赛)(线段树)

Problem Description Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless painting at a high price to someone who wants to bribe him/her on an auction, this seemed a safe way for mayor X to make money. Becaus

ACM学习历程—UESTC 1226 Huatuo&#39;s Medicine(数学)(2015CCPC L)

题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #

ACM学习历程—FZU 2140 Forever 0.5(计算几何 &amp;&amp; 构造)

Description Given an integer N, your task is to judge whether there exist N points in the plane such that satisfy the following conditions: 1. The distance between any two points is no greater than 1.0. 2. The distance between any point and the origi

ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)

Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them. The magic forms a circle, which covers those three wizards, in other words, all of them are inside or on the border of the circle. And due

ACM学习历程—FZU 2144 Shooting Game(计算几何 &amp;&amp; 贪心 &amp;&amp; 排序)

Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.) But as they don’t like using repellent while playing this kind of special (hent

ACM学习历程—HDU1392 Surround the Trees(计算几何)

Description There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him?        The

ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)

Description Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, java, pas} Input file: triangle.in Output file: triangle.out There has been considerable archeological work on the ancient Myacm culture. Many artifacts

ACM学习历程—BestCoder Round #75

1001:King's Cake(数论) http://acm.hdu.edu.cn/showproblem.php?pid=5640 这题有点辗转相除的意思.基本没有什么坑点. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #include &l