hdu 3934 Summer holiday(凸包最大内接三角形)
求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(凸包最大内接三角形)的更多相关文章
- hdu 3934 Summer holiday (凸包+旋转卡壳)
Problem - 3934 晚上为了演示给师弟看水平序的凸包是多么的好写,于是就随便找了一题凸包,25min居然1y掉了.. 代码如下: #include <cmath> #includ ...
- HDU 1827 Summer Holiday(强连通)
HDU 1827 Summer Holiday 题目链接 题意:中文题 思路:强连通缩点,每一个点的权值为强连通中最小值,然后入度为0的点就是答案 代码: #include <cstdio> ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- hdu 1348 Wall(凸包模板题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others) M ...
- POJ 1113 || HDU 1348: wall(凸包问题)
传送门: POJ:点击打开链接 HDU:点击打开链接 以下是POJ上的题: Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- HDU 6590 Code (判断凸包相交)
2019 杭电多校 1 1013 题目链接:HDU 6590 比赛链接:2019 Multi-University Training Contest 1 Problem Description Aft ...
- hdu 2202 最大三角形 (凸包)
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 1348 Wall 【凸包】
<题目链接> 题目大意: 给出二维坐标轴上 n 个点,这 n 个点构成了一个城堡,国王想建一堵墙,城墙与城堡之间的距离总不小于一个数 L ,求城墙的最小长度,答案四舍五入. 解题分析: 求 ...
- HDU 1827 Summer Holiday(tarjan求强连通分量+缩点构成新图+统计入度+一点贪心思)经典缩点入门题
Summer Holiday Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- Ring3 和Ring0 解释
这得从CPU指令系统(用于控制CPU完成各种功能的命令)的特权级别说起.在CPU的所有指令中,有一些指令是非常危险的,如果错用,将导致整个系统崩溃.比如:清内存.设置时钟等.如果所有的程序都能使用这些 ...
- ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小 错误分析
目录(?)[+] 1. 问题起因 最近在进行Oracle的一些操作时,总会遇到这个错误: ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小,错误如下: ORA-00604: ...
- OSCHina技术导向:Java开源QQ工具iQQ
iQQ 使用Java语言跨平台开发,基于腾讯WebQQ 3.0网络协议.可以使用于Java所支持的各种平台上运行.作者基于Linux(Ubuntu 12.04)系统,使用IDE NetBeans开发, ...
- hdu 1599 find the mincost route_最小环
#include <iostream> #include<cstdio> using namespace std; #define N 110 #define INF 0xff ...
- java/struts/Servlet文件下载与ftp文件上传下载
1.前端代码 使用超链接到Struts的Action或Servlet <a target="_blank" href="ftpFileAction!download ...
- 格而知之1:UIButton中imageView和titleLabel的位置调整
在使用UIButton时,有时候需要调整按钮内部的imageView和titleLabel的位置和尺寸.在默认情况下,按钮内部的imageView和titleLabel的显示效果是图片在左文字在右,然 ...
- android 自定义圆形进度条
一.通过动画实现 定义res/anim/loading.xml如下: [html] view plain copy print ? <?xml version="1.0" ...
- 在SQL Server中如何快速查找DBCC命令和语法?
DBCC命令非常好用,但是命令很多语法就很多,如何快速记忆呢?是否都要背下来.其实不用,只要能知道每个命令的作用并且记住DBCC HELP命令就可以了. --查找所有的DBCC命令 DBCC HEL ...
- Java Collection 集合类大小调整带来的性能消耗
Java Collection类的某些详细实现因为底层数据存储基于数组,随着元素数量的添加,调整大小的代价非常大.随着Collection元素增长到某个上限,调整其大小可能出现性能问题. 当Colle ...
- OAuth2.0认证介绍
OAuth2.0鉴权 返回 目录 [隐藏] 1 腾讯微博OAuth2.0认证介绍 2 获取accesstoken的两种方式 2.1 1.Authorization code grant 2.1.1 第 ...