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. TP框架的增删改

    TP添加数据有三种方式 1. //1.使用数组添加 $n = M("nation"); $arr = array("Code"=>"n007&q ...

  2. 替换jar包内指定的文件

    用Java jar 工具来替换. ① jar uvf test.jar test.class 把test.class 直接添加到jar包的根目录,也就是替换到根目录文件. ②jar uvf test. ...

  3. 【BZOJ4177】Mike的农场 最小割

    [BZOJ4177]Mike的农场 Description Mike有一个农场,这个农场n个牲畜围栏,现在他想在每个牲畜围栏中养一只动物,每只动物可以是牛或羊,并且每个牲畜围栏中的饲养条件都不同,其中 ...

  4. spring配置中的classpath

    1 classpath指WEB-INF下面的classes目录 2 配置成classpath*的话,spring会去所有的classpath中去找,包括lib下面的jar包 对于web app而言,c ...

  5. mybatis相关

    1 namespace dao中使用namespace+id一起来完成对mapper中sql statement的调用. 2 关于resultMap和parameterType parameterTy ...

  6. Java基础 - 输出

    输出在各个开发语言中起着至关重要的作用,方便编写代码时进行调试,在java中使用 System.out.println 进行输出 public class Main { public static v ...

  7. 【prometheus】学习第一篇——prometheus

    前言: 说到监控方案,市面上开源的有很多,最常用的zabbix,深入使用zabbix以后,才知道zabbix设计团队有多厉害,简直是一个完美的监控告警方案.但是在针对docker的监控上还差点,需要自 ...

  8. Django模型系统——ORM

    一.概论 1.ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过使用描 ...

  9. 动态创建selectjs 操作select和option

    1.动态创建select function createSelect(){ var mySelect = document.createElement("select"); myS ...

  10. 通过socket和Udp协议简单实现一个群体聊天工具(控制台)

    编写一个聊天程序.有收数据的部分 和 发数据的部分.这两个部分需要同时执行,这就用到多线程技术,一个线程负责收,一个现象负责发. 因为收和发动作是不一致的,所以要定义两个run方法而且这两个方法要封装 ...