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边形判断即可。
判断的时候就是枚举对角线,只有有一种情况的两条对角线相交即为凸四边形。这里采用线段相交的模板来判断。

代码:

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define inf 0x3fffffff using namespace std; struct point
{
int x, y;
}p[]; point a1, a2, a3, a4; bool inter(point a, point b, point c, point d)
{
if(
min(a.x, b.x) > max(c.x, d.x) ||
min(a.y, b.y) > max(c.y, d.y) ||
min(c.x, d.x) > max(a.x, b.x) ||
min(c.y, d.y) > max(a.y, b.y)
)
return ;
long long x1, x2, x3, x4;
x1 = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
x2 = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
x3 = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
x4 = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
return x1 * x2 < && x3 * x4 < ;
} bool fun()
{
if (inter(a1, a2, a3, a4)) return ;
if (inter(a1, a3, a2, a4)) return ;
if (inter(a1, a4, a2, a3)) return ;
return ;
} int main()
{
//freopen ("test.txt", "r", stdin);
int T;
scanf ("%d", &T);
for (int times = ; times <= T; ++times)
{
int n;
scanf ("%d", &n);
for (int i = ; i < n; ++i)
{
scanf ("%d%d", &p[i].x, &p[i].y);
}
int ans = ;
for (int i = ; i < n; ++i)
{
a1 = p[i];
for (int j = i + ; j < n; ++j)
{
a2 = p[j];
for (int k = j + ; k < n; ++k)
{
a3 = p[k];
for (int h = k + ; h < n; ++h)
{
a4 = p[h];
if (fun()) ans++;
}
}
}
}
printf ("Case %d: %d\n", times, ans);
}
return ;
}

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

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

    Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...

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

    Description   Given an integer N, your task is to judge whether there exist N points in the plane su ...

  3. ACM学习历程—BestCoder 2015百度之星资格赛1004 放盘子(策略 && 计算几何)

    Problem Description 小度熊喜欢恶作剧.今天他向来访者们提出一个恶俗的游戏.他和来访者们轮流往一个正多边形内放盘子.最后放盘子的是获胜者,会赢得失败者的一个吻.玩了两次以后,小度熊发 ...

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

    Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...

  5. 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 ...

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

    Description   Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...

  7. 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始

    以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告

  8. ACM学习历程—HDU 5512 Pagodas(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...

  9. ACM学习历程—HDU5521 Meeting(图论)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...

随机推荐

  1. Cow Contest(传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10450   Accepted: 5841 Desc ...

  2. jvm的字符串池

    1 jvm中是有专门的字符串池的内存空间的,这块空间和栈和堆不同. 2 String s = "string constant"; 这个时候,如果string pool中没有&qu ...

  3. 为system对象添加扩展方法

    ////扩展方法类:必须为非嵌套,非泛型的静态类 public static class DatetimeEx { //通过this声明扩展的类,这里给DateTime类扩展一个Show方法,只有一个 ...

  4. 获取exe文件窗口抓图,将memo转化为JPG输出

    unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  5. MD_STOCK_REQUIREMENTS_LIST_API 取MD04的MRP Element

    [转http://lz357502668.blog.163.com/blog/static/16496743201231941718527/]?MD_STOCK_REQUIREMENTS_LIST_A ...

  6. 通过systemd配置Docker

    1. systemd Service相关目录 通常情况下,我们有3种方式可以配置etcd中的service.以docker为例,1)在目录/etc/systemd/system/docker.serv ...

  7. simple -- abstract

    <?php abstract class Operation { protected $_NumberA = 0; protected $_NumberB = 0; protected $_Re ...

  8. 316python 基础之计算机基础、Python简介、变量、注释、基础数据类型初识、if、while、语句

    一.计算机基础. cpu:相当于人的大脑,运算与控制中心. 速度 飞机 内存:4G,8G,16G....暂时存储,供给cpu数据. 速度 高铁.成本高,断电即消失. 硬盘:相当于你电脑的数据库,存储着 ...

  9. curl简单封装 get post

    Curl.php <?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $ur ...

  10. Docker 镜像篇

    镜像是 Docker 容器的基石,容器是镜像的运行实例,有了镜像才能启动容器. docker两个跟镜像有关的命令: hello-world - 最小的镜像 hello-world 是 Docker 官 ...