题面

题解

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

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

我是真的忘了这道题目怎么做了,挂个\(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. voltdb数据库持久性,扩展集群

    之前在git上下载的voltdb,以及在官网下载的社区版voltdb均不支持持久性事务,和扩展集群,今天下载了企业试用版voltdb,安装过程不再赘述,记录一下我的使用过程 持久性测试 以前的 vol ...

  2. UIButton的resizableImageWithCapInsets使用解析

    UIButton的resizableImageWithCapInsets使用解析 效果: 使用的源文件: 源码: // // ViewController.m // SpecialButton // ...

  3. win10想说爱你不容易——安装.net3.5也是一个坑(已有完美解决方法)

    最终完美解决方法:经过多次波折,终于找到无法正常安装.net3.5的原因了,是因为已删除的用户还有注册表残留导致的,而且这个问题还会影响一个win10更新的安装,导致每天更新失败,撤销更新... 详见 ...

  4. memcache知识梳理

    定义: memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的.需要频繁访问数据库的网 ...

  5. TITLE: BizTalk Server 2013 Administration Console

    TITLE: BizTalk Server 2013 Administration Console------------------------------ Could not store tran ...

  6. December 03rd 2016 Week 49th Saturday

    By failing to prepare, you are preparing to fail. 不做准备,那就准备失败吧. How does the case when you had prepa ...

  7. 64位操作系统下调用32位com的问题

    Hello Guys! I am trying to create a simple VBS script to automatically open some .tif images from a ...

  8. webpack react 单独打包 CSS

    webpack react 单独打包 CSS webpack require css的方法,默认会把css 打入到js文件中,加载顺序有问题,如果需要打出独立的css文件 操作步骤: step1: 安 ...

  9. git使用,在ubuntu中

    #安装sudo apt install git要先到github官网建一个账号. #配置 你的github git config --global user.name "fanbrightu ...

  10. 第三部分 OpenStack镜像管理

    一.简介 很多源都有为OpenStack已经编译好的各种镜像了,您可以直接下载并通过使用这些镜像来熟悉OpenStack. 不过如果是为生产环境进行部署的话,您一定需要构建含有定制软件或配置的镜像文件 ...