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开始走.让最 ...
随机推荐
- 【Emit】关于System.MethodAccessException解决方案
最近学习Emit,在使用Emit动态生成对象时碰到一些"蛋疼"的问题,如下: 1.安全透明方法"XXX.XX()"尝试访问安全关键方法"YYY ...
- 九度OJ 1214:丑数 (整除)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2180 解决:942 题目描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因 ...
- zookeepeer ID生成器 (一)
目录 写在前面 1.1. ZK 的分布式命名服务 1.1.1. 分布式 ID 生成器的类型 UUID方案 1.1.2. ZK生成分布式ID 写在最后 疯狂创客圈 亿级流量 高并发IM 实战 系列 疯狂 ...
- iframe自动全屏
<iframe src="weixin.php" id="adlistpage" name="adlistpage" framebor ...
- ABAP操作EXCEL (号称超级版)
[转自http://www.cnblogs.com/VerySky/articles/2170014.html] *------------------------------------------ ...
- 移动端 触摸事件 ontouchstart、ontouchmove、ontouchend、ontouchcancel[转]
转:http://www.cnblogs.com/irelands/p/3433628.html 1.Touch事件简介pc上的web页面鼠 标会产生onmousedown.onmouseup.onm ...
- 关于VMAX中存储资源池(SRP)
Storage Resource Pool中的相关元素 SRP由一个或多个数据池组成,这些数据池包含了预配置的数据(或TDAT)设备,可为创建和呈现给主机与应用程序的精简设备(TDEVS) 提供存储. ...
- 第7条:用列表推导式来取代map和filter
核心知识点: 1.列表推导式要比内置的map和filter函数清晰,因为它无需额外编写lambda表达式. 2.列表推导式可以跳过输入列表中的某些元素,如果改用map来做,那就必须辅以filter方能 ...
- 3django url name详解
打开urls.py from django.conf.urls import url from django.contrib import admin from calc import views a ...
- 每天一个Linux命令(35)wc命令
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. (1)用法: 用法: wc [选项] [文件]. ...