题面

题解

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

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

我是真的忘了这道题目怎么做了,挂个\(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. webservice双向验证

    ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtoco ...

  2. Entity Framework 更新模式之Attach与EntityState.Modified模式的区别

    数据库中有一个City表 初始时数据: 实体类与Fluent Api配置映射 public class City { public int Id { get; set; } public string ...

  3. WinForm 应用程序禁止多个进程运行

    方法一: 禁止多个进程运行 using System; using System.Collections.Generic; using System.Linq; using System.Window ...

  4. 用NSOperation写下载队列

    用NSOperation写下载队列 说明 1. 支持缓存机制 2. 图片都是在主线程中加载 3. 文件名用了md5加密 *这东西被人写烂了,但大伙如果对NSOperation不熟悉的话,可以看看本人的 ...

  5. [翻译] RAReorderableLayout

    RAReorderableLayout A UICollectionView layout which you can move items with drag and drop. 一种UIColle ...

  6. Log4net 使用之 日期字段格式化

    Log4net 是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介. 之前Log4net的日期字段Data一直采 ...

  7. Qt如何设置应用ico图标

    第一步,创建ico文件.将ico图标文件复制到工程文件夹目录中(注意必须是图标文件,任何格式的改后缀都不行) ,重命名为"myico.ico“.然后在该目录中右击,新建文本文档,并输入一行代 ...

  8. swift直接赋值与引用赋值都会触发willSet

    class baseGoo{ var isScannerRunning = false { willSet{ print(newValue) } } var desp:String = "& ...

  9. VMware三个版本号workstation、server、esxi的差别

    VMware三个版本号 workstation: 单机级.用在个人桌面系统中.须要操作系统支持 servier:工作组级,用于服务器.须要操作系统支持 esxi:企业级,用于服务器,不须要操作系统支持 ...

  10. apache ActiveMQ之初体验

    版权声明: https://blog.csdn.net/zdp072/article/details/27237549 一. 开篇语 继上一篇weblogic中使用jms发送和接受消息的文章后, 本文 ...