POJ2079 Triangle
题面
题解
我什么时候会过这种东西???(逃
旋转卡壳板子题(听说这个算法有十六种读音???
我是真的忘了这道题目怎么做了,挂个\(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的更多相关文章
- 【poj2079】 Triangle
http://poj.org/problem?id=2079 (题目链接) 题意 求凸包内最大三角形面积 Solution 旋转卡壳. 只会n²的做法,但是竟然过了.就是枚举每一个点,然后旋转卡壳另外 ...
- POJ2079:Triangle——题解
http://poj.org/problem?id=2079 题目大意:求最大面积的三角形. —————————————————— 可以知道,最大面积的三角形的顶点一定是最大凸包的顶点. 接下来就是O ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
随机推荐
- Sqlserver2014 迁移数据库
由于当初安装sqlserver 的时候选择默认安装的路径,导致现在c盘爆满,安装不了其它软件.因此想到了迁移数据库,网上搜索了一些简介,但是缺少一些步骤,导致数据库附加的时候失败.现总结如下: 1.将 ...
- 查询会龄 sql部分
AND ( case when ${fld:vc_age} = '1' then ((current_date-d.c_idate::date)/30)<3 when ...
- 12 Things Developers Will Love About Oracle Database 12c Release 2
by Chris Saxon-Oracle It's Here: Oracle Database 12c Release 2 (12.2) Is available on Oracle Cloud. ...
- Linux vim命令详解
vi: o 处于下一行编辑模式 A 处于编辑的后面 ==>END gg 文件的开头 98gg 跳转到第98行 Shift + G 文件结尾 $ 文件行结尾 ^ 文件行开头 ==> ...
- Linux zip命令详解
zip常见命令参数 Usage: zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list] The ...
- 申请Let’s Encrypt永久免费SSL证书过程教程及常见问题
配置证书https://easy.zhetao.com/ 虽然目前Let’s Encrypt免费SSL证书默认是90天有效期,但是我们也可以到期自动续约,不影响我们的尝试和使用,为了考虑到文章的真 ...
- oracle 启动报错ORA-27125解决方案
脚本: oracle@edwdb:~> id uid=(oracle) gid=(oinstall) (oinstall),(dba) oracle@edwdb:~> su - root ...
- yii 验证码功能的实现
首先知晓我们在使用验证码的时候通常是和我们的表单小部件配合使用首先我们创建model层 新建一个php文件 名字叫做Verifycode.php 要在我们的model层 创建我们的验证码的验证规则,我 ...
- September 09th 2017 Week 36th Saturday
Don't wait to be lonely, to recognize the value of a friend. 不要等到孤独了,才明白朋友的价值. Don't wait to be left ...
- Mongodb极简实践
MongoDB 极简实践入门 1. 为什么用MongoDB? 传统的计算机应用大多使用关系型数据库来存储数据,比如大家可能熟悉的MySql, Sqlite等等,它的特点是数据以表格(table)的形式 ...