求n个点能组成的最大三角形,一发旋转卡壳模板题。。。

    #include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define PB push_back
#define LL long long
#define eps 1e-10
#define debug puts("**debug**")
using namespace std; struct Point
{
double x, y;
Point(double x=0, double y=0) : x(x), y(y) {}
};
typedef Point Vector; Vector operator + (Vector a, Vector b) { return Vector(a.x+b.x, a.y+b.y) ; }
Vector operator - (Point a, Point b) { return Vector(a.x-b.x, a.y-b.y); }
Vector operator * (Vector a, double p) { return Vector(a.x*p, a.y*p); }
Vector operator / (Vector a, double p) { return Vector(a.x/p, a.y/p); } bool operator < (const Point& a, const Point& b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
} int dcmp(double x)
{
if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;
}
bool operator == (const Point& a, const Point& b)
{
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}
double Cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }
double Dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y ;}
double Length(Vector a) { return sqrt(Dot(a, a)); } int ConvexHull(Point* p, int n, Point* ch)
{
sort(p, p+n);
int m = 0;
REP(i, n)
{
while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <=0) m--;
ch[m++] = p[i];
}
int k = m;
FD(i, n-2, 0)
{
while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
if(n > 1) m--;
return m;
} double RC_Distance(Point* ch, int n) //凸包直径
{
int q = 1;
double ans = 0;
ch[n] = ch[0];
REP(p, n)
{
while(Cross(ch[q+1]-ch[p+1], ch[p]-ch[p+1]) > Cross(ch[q]-ch[p+1], ch[p]-ch[p+1])) q = (q+1)%n;
ans = max(ans, max(Length(ch[p]-ch[q]), Length(ch[p+1]-ch[q+1])));
}
return ans;
} double RC_Triangle(Point* res,int n)// 凸包最大内接三角形
{
if(n<3) return 0;
double ans=0, tmp;
res[n] = res[0];
int j, k;
REP(i, n)
{
j = (i+1)%n;
k = (j+1)%n;
while((j != k) && (k != i))
{
while(Cross(res[j] - res[i], res[k+1] - res[i]) > Cross(res[j] - res[i], res[k] - res[i])) k= (k+1)%n;
tmp = Cross(res[j] - res[i], res[k] - res[i]);if(tmp > ans) ans = tmp;
j = (j+1)%n;
}
}
return ans;
} Point read_point()
{
Point a;
scanf("%lf%lf", &a.x, &a.y);
return a;
} const int maxn = 1000010;
int n;
double x, y, w;
Point p[maxn], ch[maxn]; int main()
{
while(~scanf("%d", &n))
{
REP(i, n) p[i] = read_point();
int m = ConvexHull(p, n, ch);
double ans = RC_Triangle(ch, m);
printf("%.2f\n", ans/2);
}
return 0;
}

hdu 3934 Summer holiday(凸包最大内接三角形)的更多相关文章

  1. hdu 3934 Summer holiday (凸包+旋转卡壳)

    Problem - 3934 晚上为了演示给师弟看水平序的凸包是多么的好写,于是就随便找了一题凸包,25min居然1y掉了.. 代码如下: #include <cmath> #includ ...

  2. HDU 1827 Summer Holiday(强连通)

    HDU 1827 Summer Holiday 题目链接 题意:中文题 思路:强连通缩点,每一个点的权值为强连通中最小值,然后入度为0的点就是答案 代码: #include <cstdio> ...

  3. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

    链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  4. hdu 1348 Wall(凸包模板题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. POJ 1113 || HDU 1348: wall(凸包问题)

    传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissio ...

  6. HDU 6590 Code (判断凸包相交)

    2019 杭电多校 1 1013 题目链接:HDU 6590 比赛链接:2019 Multi-University Training Contest 1 Problem Description Aft ...

  7. hdu 2202 最大三角形 (凸包)

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. HDU 1348 Wall 【凸包】

    <题目链接> 题目大意: 给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入. 解题分析: 求 ...

  9. HDU 1827 Summer Holiday(tarjan求强连通分量+缩点构成新图+统计入度+一点贪心思)经典缩点入门题

    Summer Holiday Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. Gradle方式构建Java多项目

    0: 安装IDEA:Linux 上只需下载IDEA的包 并且将路径配置在PATH全局变量中./etc/profile export PATH=$PATH:/opt/Software/IDEA/idea ...

  2. MVC4商城项目一:框架设计

    代码已托管在  https://code.csdn.net/denghao156/ktnmb_mvc4 先上图,设计模式参考:ddmvc4.codeplex.com 一.unintofwork  设计 ...

  3. javac: cannot execute binary file

    # java/jdk1.6.0_12/bin/javac-bash: java/jdk1.6.0_12/bin/javac: cannot execute binary file   后来检验,检查了 ...

  4. 4.1. 如何在Windows环境下开发Python

    4.1. 如何在Windows环境下开发Python 4.1. 如何在Windows环境下开发Python 4.1.1. Python的最原始的开发方式是什么样的 4.1.1.1. 找个文本编辑器,新 ...

  5. Eidtplus常用快捷键

    文件 新建普通文本 Ctrl+N 新建普通的文本文档 新建浏览器窗口 Ctrl+Shift+B 新建浏览器窗口 新建 HTML 页 Ctrl+Shift+N 创建一个空白的 HTML 页面 打开 Ct ...

  6. Knots(找规律)

    Knots Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  7. Longge的问题(欧拉,思维)

     Longge的问题 Submit Status Practice HYSBZ 2705 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一 ...

  8. OpenCV——PS 图层混合算法(一)

    详细的算法原理能够參考 PS图层混合算法之中的一个(不透明度,正片叠底,颜色加深,颜色减淡) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #de ...

  9. 【最大流】【HDU3338】【Kakuro Extension】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3338 题目大意:填数字,使白色区域的值得和等于有值得黑色区域的相对应的值,用网络流来做 题目思路:增加 ...

  10. CSS学习笔记(1):选择器

    一.元素选择器 HTML文档元素就是最基本的选择器 如: <!DOCTYPE html> <html lang="en"> <head> < ...