题目传送门

题意:给了n个点的坐标,问能有几个凸四边形

分析:数据规模小,直接暴力枚举,每次四个点判断是否会是凹四边形,条件是有一个点在另外三个点的内部,那么问题转换成判断一个点d是否在三角形abc内

    易得S (abd) + S (acd) + S (bcd) == S (abc),求三角形面积

收获:比赛时没写出来,没想到用面积就轻松搞定,脑子有点乱,开始敲了计算几何点是否在凸多边形内的模板,WA了,整个人都不好了。收获就是要把计算几何的基础补上来

代码:

/************************************************
* Author :Running_Time
* Created Time :2015-8-23 13:40:19
* File Name :H.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 33;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const double PI = acos (-1.0);
struct Point {
double x, y;
}; int n;
Point pp[N]; double area(Point a, Point b, Point c) {
return fabs (0.5 * (a.x * b.y + c.x * a.y + b.x * c.y - c.x * b.y - a.x * c.y - b.x * a.y));
} bool cal(Point a, Point b, Point c, Point d) {
double sum = area (a, b, d) + area (a, c, d) + area (b, c, d);
double tot = area (a, b, c);
if (fabs (sum - tot) < EPS) return false;
return true;
} bool judge(Point a, Point b, Point c, Point d) {
if (!cal (a, b, c, d)) return false;
if (!cal (a, b, d, c)) return false;
if (!cal (a, d, c, b)) return false;
if (!cal (d, b, c, a)) return false;
return true;
} int work(void) {
int ret = 0;
for (int i=1; i<=n; ++i) {
for (int j=i+1; j<=n; ++j) {
for (int k=j+1; k<=n; ++k) {
for (int l=k+1; l<=n; ++l) {
if (judge (pp[i], pp[j], pp[k], pp[l])) ret++;
}
}
}
} return ret;
} int main(void) {
int T, cas = 0; scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%lf%lf", &pp[i].x, &pp[i].y);
}
printf ("Case %d: %d\n", ++cas, work ());
} return 0;
}

  

暴力(判凸四边形) FZOJ 2148 Moon Game的更多相关文章

  1. FZU Problem 2148 Moon Game (判断凸四边形)

    题目链接 题意 : 给你n个点,判断能形成多少个凸四边形. 思路 :如果形成凹四边形的话,说明一个点在另外三个点连成的三角形内部,这样,只要判断这个内部的点与另外三个点中每两个点相连组成的三个三角形的 ...

  2. Moon Game (凸四边形个数,数学题)

    Problem 2148 Moon Game Accept: 24    Submit: 61 Time Limit: 1000 mSec    Memory Limit : 32768 KB Pro ...

  3. FZOJ Problem 2148 Moon Game

                                                                                                  Proble ...

  4. FZU 2148 Moon Game --判凹包

    题意:给一些点,问这些点能够构成多少个凸四边形 做法: 1.直接判凸包 2.逆向思维,判凹包,不是凹包就是凸包了 怎样的四边形才是凹四边形呢?凹四边形总有一点在三个顶点的内部,假如顶点为A,B,C,D ...

  5. fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)

    题目:http://acm.fzu.edu.cn/problem.php?pid=2148 题意:给出n个点,判断可以组成多少个凸四边形. 思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是 ...

  6. ACM: FZU 2148 Moon Game - 海伦公式

     FZU 2148  Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  7. FZU 2148 moon game (计算几何判断凸包)

    Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  8. HDU3629(凸四边形的个数)

    HDU 3629 计算几何 题目描述:给你n个点(4~700), 问你能够成多少个不同的凸四边形. 解题报告: 暴力的话C(700,4)必然超时,发现,任何一个凹包必然是其中一点在其它3点构成的三角形 ...

  9. FZU 2148 Moon Game

    Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

随机推荐

  1. 【转】apache storm 内置的定时机制

    原文:http://www.cnblogs.com/kqdongnanf/p/4778672.html ------------------------------------------------ ...

  2. Vue调试工具 vue-devtools

    vue-devtools是一款基于chrome浏览器的插件,可以帮我们快速调试vue项目 vue-devtools手动安装: 第一步:找到vue-devtools的github项目(https://g ...

  3. hdu 4902 Nice boat--2014 Multi-University Training Contest 4

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...

  4. 分享:Mac与Phy组成原理的简单分析

    原文链接:http://blog.chinaunix.net/uid-20528014-id-3050217.html 1.General 下图是网口结构简图.网口由CPU.MAC和PHY三部分组成. ...

  5. Educational Codeforces Round 18 C. Divide by Three DP

    C. Divide by Three   A positive integer number n is written on a blackboard. It consists of not more ...

  6. http://www.freetds.org/userguide/what.htm

    FreeTDS is re-implementation of C libraries originally marketed by Sybase and Microsoft SQL Server. ...

  7. 《CMake实践》笔记二:INSTALL/CMAKE_INSTALL_PREFIX【转】

    本文转载自:http://www.cnblogs.com/52php/p/5681751.html 四.更好一点的Hello World 没有最好,只有更好 从本小节开始,后面所有的构建我们都将采用  ...

  8. Android JNI MAC OS环境配置

    前言—JNI技术简介 JNI是Java Native Interface的缩写,即“Java本地调用”,它是Java世界和Native世界的中介桥梁.其中Native世界一般指C/C++的世界.众所周 ...

  9. Linux服务器性能问题

    如何快速分析出现性能问题的Linux服务器 https://www.cnblogs.com/leixiaobai/category/1246164.html Brendan Gregg曾经分享过当遇到 ...

  10. 去除inline-block的间隙

    产生间隙的原因就是标签之间的空格,去除的方法: 1 设置父元素的font-size:0;空格字符的宽高都为0, <div class="demo1 demo2"> &l ...