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 ...
随机推荐
- 12.2Data Guard新特性--使用DBMS_DBCOMP.DBCOMP数据比较
Oracle Data Guard会主动对Hot数据(数据正被读取或修改)执行验证, 无论是primary还是standby,但对于那些Cold数据不会做任何检查和校验.所以在12.2版本 ...
- [UI] 精美UI界面欣赏[7]
精美UI界面欣赏[7] 视频地址: http://v.youku.com/v_show/id_XOTM0MDUzNTg0.html UI介绍地址: http://www.zhihu.com/quest ...
- 通过runtime打印出对象所有属性的值
通过runtime打印出对象所有属性的值 今天给给大家提供的关于NSObject的category,通过runtime打印属性的值,相当有用哦,以后你再也不用每个对象都通过NSLog来逐个打印属性值了 ...
- 审计系统---初识堡垒机180501【all】
堡垒机背景[审计系统] SRE是指Site Reliability Engineer (/运维工程师=运行维护 业务系统) 运维: 维护系统,维护业务,跟业务去走 防火墙: 禁止不必要的访问[直接访问 ...
- Sharepoint 2013 - 直接显示Doclib中的html page
缺省的HTML不能直接显示,会被要求存盘.以下操作可以修改 Go to Central Administration Select Manage web applications Select the ...
- 02-urllib库的get请求方式
对于urllib中的get请求方式,可以直接传入url的连接即可访问页面,但是对于要传入关键字的话,也可以用quote进行编码再传入. 案例如下: #get请求搜索参数如何添加 import urll ...
- adb shell 运行时报错"adb server version (26) doesn't match this client (39); killing..."的解决方案
adb即 Android Debug Bridge 是一个通用的命令行工具,可用于通过PC端对连接的Android模拟器设备或连接至电脑的真实物理设备进行命令行操作.目前,许多软件均会借助 adb 工 ...
- DIV+CSS:如何编写代码才能更有效率
如何编写CSS代码才能更有效率?这是许多网页制作者与开发者都关心的问题.大概没有什么魔法,可以保证一下就把你的样式表缩小到百分之多少,但合理的 CSS 编码与组织技巧,的确能够帮助你的更有效率地写出更 ...
- Linux环境变量配置文件/etc/profile、/etc/bashrc、~/.bashrc的区别以及一些隐藏文件的作用
①/etc/profile: 该文件登录操作系统时,为每个用户设置环境信息,当用户第一次登录时,该文件被执行.也就是说这个文件对每个shell都有效,用于获取系统的环境信息. ②/etc/bashrc ...
- crontab定时执行
一.crond简介 crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cro ...