fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)
题目:http://acm.fzu.edu.cn/problem.php?pid=2148
题意:给出n个点,判断可以组成多少个凸四边形。
思路:
因为n很小,所以直接暴力,判断是否为凸四边形的方法是:
如果4个点中存在某个点D,Sabd + Sacd + Sbcd = Sabc,则说明是凹四边形。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-; //定义成double类型 struct point
{
int x, y;
} p[];
double area(point a, point b, point c)
{
return (fabs((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x))/); //一定要fabs(),有可能为负的,
}
bool ok(point a, point b, point c, point d)
{
if(fabs(area(b,c,d)-area(a,b,c)-area(a,c,d)-area(a,b,d)) < eps)
return false;
return true;
}
int main()
{
int t, i, j, n, k, ans, a, b;
scanf("%d", &t);
for(k = ; k <= t; k++)
{
ans = ;
scanf("%d", &n);
for(i = ; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y); if(n<)
printf("Case %d: %d", k, ans);
else
{
for(i = ; i < n; i++)
for(j = i+; j < n; j++)
for(a = j+; a < n; a++)
for(b = a+; b < n; b++)
if(ok(p[i],p[j],p[a],p[b])&&ok(p[j],p[i],p[a],p[b])
&&ok(p[a],p[i],p[j],p[b])&&ok(p[b],p[i],p[j],p[a]))
{
ans++;
}
printf("Case %d: %d\n", k, ans);
}
}
return ;
}
fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)的更多相关文章
- FZU Problem 2148 Moon Game (判断凸四边形)
题目链接 题意 : 给你n个点,判断能形成多少个凸四边形. 思路 :如果形成凹四边形的话,说明一个点在另外三个点连成的三角形内部,这样,只要判断这个内部的点与另外三个点中每两个点相连组成的三个三角形的 ...
- FZOJ Problem 2148 Moon Game
Proble ...
- Moon Game (凸四边形个数,数学题)
Problem 2148 Moon Game Accept: 24 Submit: 61 Time Limit: 1000 mSec Memory Limit : 32768 KB Pro ...
- ACM: FZU 2148 Moon Game - 海伦公式
FZU 2148 Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- FZu Problem 2233 ~APTX4869 (并查集 + sort)
题目链接: FZu Problem 2233 ~APTX4869 题目描述: 给一个n*n的矩阵,(i, j)表示第 i 种材料 和 第 j 种材料的影响值,这个矩阵代表这n个物品之间的影响值.当把这 ...
- FZu Problem 2236 第十四个目标 (线段树 + dp)
题目链接: FZu Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...
- 翻翻棋(找规律问题)(FZU Problem 2230)
题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...
- FZU 2148 moon game (计算几何判断凸包)
Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- FZU 2148 Moon Game
Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
随机推荐
- cocos2dx中的动作
CCAction是cocos2dx中专门用来处理动作相关的类,几乎所有的与动作相关的类都是从它派生而来的.而CCAction继承自CCObject class CCFiniteTimeAction : ...
- WPF 多线程处理(4)
WPF 多线程处理(1) WPF 多线程处理(2) WPF 多线程处理(3) WPF 多线程处理(4) WPF 多线程处理(5) WPF 多线程处理(6) 开始一个线程处理读取的文件并且更新到list ...
- Careercup - Facebook面试题 - 5110993575215104
2014-04-30 16:12 题目链接 原题: The beauty of a number X is the number of 1s in the binary representation ...
- 1486: [HNOI2009]最小圈 - BZOJ
在机房的小伙伴提醒是二分之后,我想到了是判负环,所以我用spfa,而且我保持dis都是小于等于0,本以为这样就能过了,可是还是有一个点达到了3.8s左右(其他都是0.0几秒) 所以还是写了dfs版 ...
- boost序列化
#include <iostream> #include <boost/serialization/serialization.hpp> #include <boost/ ...
- 消除SDK更新时的“https://dl-ssl.google.com refused”异常
原地址:http://blog.csdn.net/x605940745/article/details/17911115 消除SDK更新时的“https://dl-ssl.google.com ref ...
- Javascript的动态运动(1)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- hdu1301Jungle Roads
http://acm.hdu.edu.cn/showproblem.php?pid=1301 最小生成树模板题 #include<iostream> #include<stdio.h ...
- Mac 下 docker安装
http://www.th7.cn/system/mac/201405/56653.shtml Mac 下 docker安装 以及 处理错误Cannot connect to the Docker d ...
- Highcharts中初始化最大值与最小值的柱状图
<!doctype html> <html lang="en"> <head> <script type="text/javas ...