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
4
0 0
100 0
0 100
100 100
4
0 0
100 0
0 100
10 10
Sample Output
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(计算几何)的更多相关文章
- ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)
Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...
- 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 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1004 放盘子(策略 && 计算几何)
Problem Description 小度熊喜欢恶作剧.今天他向来访者们提出一个恶俗的游戏.他和来访者们轮流往一个正多边形内放盘子.最后放盘子的是获胜者,会赢得失败者的一个吻.玩了两次以后,小度熊发 ...
- ACM学习历程—HDU4720 Naive and Silly Muggles(计算几何)
Description Three wizards are doing a experiment. To avoid from bothering, a special magic is set ar ...
- 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 ...
- ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)
Description Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
随机推荐
- Scout YYF I (概率+矩阵快速幂)
YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's ba ...
- 我的Android进阶之旅------>启动Activity的标准Action和标准Category
Android内部提供了大量标准的Action和Category常量. 除了参考本文外,您还可以参考了以下链接: http://developer.android.com/reference/andr ...
- IaaS,PaaS,Saas 云服务的介绍
云服务只是一个统称,可以分成三大类. IaaS:基础设施服务,Infrastructure-as-a-service PaaS:平台服务,Platform-as-a-service SaaS:软件服务 ...
- python __name__及__main()__的妙处
#hello.py def sayHello(): str="hello" print(str); if __name__ == "__main__": pri ...
- JPA 多表分页查询
业务场景:大学生毕业后统计毕业去向.学生实体和毕业去向实体一对一关系. 实体: @Entity @Data @Table(name = "t_s_student") public ...
- BAPI_SALESORDER_CREATEFROMDAT2 创建退货SO
BAPI_SALESORDER_CREATEFROMDAT2创建退货订单时,会出现以下错误:不允许业务对象 BUS2032 和销售凭证类别 H 的组合. 解决办法: 采用/原BAPI的内嵌BAPI: ...
- SAP basis 常用事物
1.创建一个新的用户 完成client创建和拷贝后,在开始正式工作之前,需要创建新的用户. 用这个用户进行工作.默认ddic和sap*用户不要用于实际的业务. 创建用户的过程很简单,只要以su01 ...
- 如何禁止eclipse对js文件的校验(building validate)
在项目(project)上点击右键,依次选择1.Select Properties -> JavaScript -> Include Path2.Select Source tab. ( ...
- (转)Javascript模块化编程(二):AMD规范
这个系列的第一部分介绍了Javascript模块的基本写法,今天介绍如何规范地使用模块. (接上文) 七.模块的规范 先想一想,为什么模块很重要? 因为有了模块,我们就可以更方便地使用别人的代码,想要 ...
- 【python】将excel转成json
excel格式如下: 转换后如下 {"BD": 1375.0, "BE": 829.0, "BF": 3.0, "BG" ...