题面

题解

我什么时候会过这种东西???(逃

旋转卡壳板子题(听说这个算法有十六种读音???

我是真的忘了这道题目怎么做了,挂个\(blog\),等我学会了再写题解

我的代码里居然有注释???好像还是蒯的上面那个博客的

运算符之间没有空格?居然using namespace std???果然是上古代码

本来我还想用模拟退火过的。。。

代码

好丑,凑合着看吧。。。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<ctime>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std; const int maxn(50010);
inline double sqr(const double &x) { return x*x; }
struct point
{
double x, y;
point() {}
point(double dx, double dy) : x(dx), y(dy) {}
inline void read() { scanf("%lf%lf", &x, &y); }
inline bool operator < (const point &rhs) const
{
return x<rhs.x || (x==rhs.x && y<rhs.y);
} inline point operator - (const point &rhs)
{
return point(x-rhs.x, y-rhs.y);
} inline double operator * (const point &rhs)
{
return x*rhs.y-rhs.x*y;
}
}p[maxn]; int n, stk[maxn], top;
inline double dis(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
inline bool goleft(point a, point b, point c)
{
double s((b-a)*(c-a));
return s<0 || (s==0 && dis(a, b) >= dis(a, c));
} inline double area(point a, point b, point c) { return abs((b-a) * (c-a) * 0.5); }
inline bool cmp(const point &a, const point &b) { return goleft(p[1], a, b); } inline double rotating_calipers()
{
int a = 1, b = 2;
double ans = 0;
p[stk[0]] = p[stk[top]];
for(RG int i=0;i<top;i++)
{
while(area(p[stk[i]], p[stk[a]], p[stk[b + 1]]) > area(p[stk[i]], p[stk[a]], p[stk[b]])) b = (b + 1) % top; // 定点i, a, b,先i,a固定,让b旋转找到最大的面积三角形,还是利用了凸包的单峰函数
ans = max(ans, area(p[stk[i]], p[stk[a]], p[stk[b]]));
while(area(p[stk[i]], p[stk[a + 1]], p[stk[b]]) > area(p[stk[i]], p[stk[a]], p[stk[b]])) a = (a + 1) % top; // i, a固定, b旋转, 找到最大的三角形面积, 比较记录.
ans = max(ans, area(p[stk[i]], p[stk[a]], p[stk[b]]));
}
return ans;
} int main()
{
while(~scanf("%d", &n) && ~n)
{
for(RG int i=1;i<=n;i++) p[i].read();
int first=1;
for(RG int i=2;i<=n;i++) if(p[i]<p[first]) first=i;
swap(p[1], p[first]);
sort(p+2, p+n+1, cmp);
p[n+1]=p[1]; stk[1]=1; stk[top=2]=2;
for(RG int i=3;i<=n+1;i++)
{
while(top>1 && goleft(p[stk[top-1]], p[i], p[stk[top]])) --top;
stk[++top]=i;
}
top--; printf("%.2lf\n", rotating_calipers());
}
return 0;
}

POJ2079 Triangle的更多相关文章

  1. 【poj2079】 Triangle

    http://poj.org/problem?id=2079 (题目链接) 题意 求凸包内最大三角形面积 Solution 旋转卡壳. 只会n²的做法,但是竟然过了.就是枚举每一个点,然后旋转卡壳另外 ...

  2. POJ2079:Triangle——题解

    http://poj.org/problem?id=2079 题目大意:求最大面积的三角形. —————————————————— 可以知道,最大面积的三角形的顶点一定是最大凸包的顶点. 接下来就是O ...

  3. [LeetCode] Triangle 三角形

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  4. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  5. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  6. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  7. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  8. POJ 1163 The Triangle(简单动态规划)

    http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  9. Triangle - Delaunay Triangulator

    Triangle - Delaunay Triangulator  eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...

随机推荐

  1. Linux HugePages 配置与 Oracle 性能关系说明

    一.  HugePages 说明 1.1 HugePages 介绍 HugePages is a feature integrated into the Linux kernel with relea ...

  2. 使用GPUImage渲染图片教程

    使用GPUImage渲染图片教程 Prepare - 准备 GPUImage开源库并不像普通的开源库那样子,拖进你的工程中就可以用.以下将详细的告诉你如何将GPUImage导入到你的工程当中. 首先上 ...

  3. 修改UIView的默认Layer后,修改View的值会动态修改Layer的值

    修改UIView的默认Layer后,修改View的值会动态修改Layer的值 效果图: 如上图所示,当我们修改了一个UIView的子类中的Layer内置类型时(如上图中我们将CALayer直接替换成了 ...

  4. UNIX高级环境编程(7)标准IO函数库 - 二进制文件IO,流定位,创建临时文件和内存流

    1 二进制IO(Binary IO) 在前一篇我们了解了逐字符读写和逐行读写函数. 如果我们在读写二进制文件,希望以此读写整个文件内容,这两个函数虽然可以实现,但是明显会很麻烦且多次循环明显效率很低. ...

  5. windows下PyCharm安装及使用

    一.首先安装pycharm,可以参考这篇文章:http://www.jianshu.com/p/042324342bf4 1.win10_X64,其他Win版本也可以. 2.PyCharm版本:Pro ...

  6. 【教程】【FLEX】#004 反射机制

    总结: 目前用到反射的主要有两个方法 1.  getDefinitionByName    //根据类名,返回对象(反射实例化对象) 2.  describeType                 ...

  7. hihocoder Round #c1(hihoCoder太阁最新面经算法竞赛1 )

    Test链接:https://cn.vjudge.net/contest/231849 选自hihoCoder太阁最新面经算法竞赛1 更多Test:传送门 A:区间求差 给一组区间集合A和区间集合B, ...

  8. 动态代理与HOOK(与oc isa 替换)

    HOOK:面向函数,解决函数调用拦截与替换的问题: 动态代理:面向对象,解决对象的动态替换问题: 动态代理的实现方案: 1.经典代理机制: 2.子类化机制:oc语言的isa替换是这额解决方案的经典案例 ...

  9. CF600E:Lomsat gelral(线段树合并)

    Description 一棵树有n个结点,每个结点都是一种颜色,每个颜色有一个编号,求树中每个子树的最多的颜色编号的和. Input 第一行一个$n$.第二行$n$个数字是$c[i]$.后面$n-1$ ...

  10. 【洛谷】【堆】P1168 中位数

    [题目描述:] 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], …, A[2k - 1]的中位数.即前1,3,5,……个数的中位数. ...