POJ 2079
呃,不知道我用的算不算卡壳,总有点枚举的意思。
先求凸包,然后,枚举其中一点,再枚举另一点作为结尾,这个向量旋转一周后,求出最大值面积。这里面用的是旋转卡壳判断的那个式子。
PS:下一篇和这题是一样题意,但用这题的写法去过下一题,是过不了的。但这个写法在POJ 上是400MS,而下一题的写法在POJ上是1000MS。。汗了。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std; struct point{
int x,y;
}p[50050];
int n; int ans[50050],st[50050],cnt,stop; bool cmp(point A, point B){
if(A.y<B.y) return true;
else if(A.y==B.y){
if(A.x<B.x) return true;
}
return false;
} int multi(point a,point b,point c){
point p1; p1.x=a.x-c.x; p1.y=a.y-c.y;
point p2; p2.x=b.x-c.x; p2.y=b.y-c.y;
return p1.x*p2.y-p1.y*p2.x;
} void slove(){
cnt=stop=0;
st[stop++]=0; st[stop++]=1;
for(int i=2;i<n;i++){
while(stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])>0) stop--;
st[stop++]=i;
}
for(int i=0;i<stop;i++)
ans[cnt++]=st[i];
stop=0; st[stop++]=n-1; st[stop++]=n-2;
for(int i=n-3;i>=0;i--){
while(stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])>0) stop--;
st[stop++]=i;
}
for(int i=1;i<stop;i++)
ans[cnt++]=st[i];
} double Triangle(point a,point b,point c){
point p1; p1.x=a.x-c.x; p1.y=a.y-c.y;
point p2; p2.x=b.x-c.x; p2.y=b.y-c.y;
return fabs((p1.x*p2.y-p1.y*p2.x)*1.0)/2.0;
} double Area(){
int q;
double anst=0;
for(int i=0;i<cnt;i++){
q=i+1;
for(int j=i+1;j<cnt;j++){
while(Triangle(p[ans[i]],p[ans[j]],p[ans[q]])<Triangle(p[ans[i]],p[ans[j]],p[ans[(q+1)%cnt]]))
q=(q+1)%cnt;
anst=max(anst,Triangle(p[ans[i]],p[ans[j]],p[ans[q]]));
}
}
return anst;
} int main(){
while(scanf("%d",&n)!=EOF){
if(n==-1) break;
for(int i=0;i<n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp);
slove();
double anst=0;
anst=max(anst,Area());
printf("%.2lf\n",anst);
}
return 0;
}
POJ 2079的更多相关文章
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- ●POJ 2079 Triangle
题链: http://poj.org/problem?id=2079 题解: 计算几何,凸包,旋转卡壳 复杂度O(N^2),(O(N)什么的就不说了,我觉得我看过的O(N)方法正确性都有问题,虽然有些 ...
- POJ 2079 Triangle (凸包+旋转卡壳)
[题目链接] http://poj.org/problem?id=2079 [题目大意] 给出一些点,求出能组成的最大面积的三角形 [题解] 最大三角形一定位于凸包上,因此我们先求凸包,再在凸包上计算 ...
- poj 2079 Triangle(旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 8917 Accepted: 2650 Descript ...
- POJ 2079 Triangle [旋转卡壳]
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9525 Accepted: 2845 Descript ...
- poj 2079(旋转卡壳求解凸包内最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9060 Accepted: 2698 Descript ...
- POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 7625 Accepted: 2234 Descript ...
- POJ - 2079:Triangle (旋转卡壳,求最大三角形)
Given n distinct points on a plane, your task is to find the triangle that have the maximum area, wh ...
- POJ 2079 最大三角形面积(凸包)
Triangle Description Given n distinct points on a plane, your task is to find the triangle that have ...
随机推荐
- bzoj2595 [Wc2008]游览计划——斯坦纳树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2595 今天刚学了斯坦纳树,还不太会,写一道题练习一下: 参考了博客:http://www.c ...
- easyui+struts2:datagrid无法不能得到数据
转自:https://bbs.csdn.net/topics/390980437 easyui+struts2:datagrid无法访问到指定action: userlist.jsp部分代码: XML ...
- 用JS将指定时间转化成用户当地时区的时间
公司的项目是面向海外用户的,但是最初的设计没考虑到时差问题,存入数据库的时间都是东八区的时间,导致现在补救有点坑爹...... 有一个需求是,产品详细页需要注明此款产品的开售时间,当海外的用户来访问这 ...
- Docker 探索安装WordPress+Mysql8.0
拉取MYSQL,注意默认是8.0版本,连接加密方式有变化 docker pull mysql 运行MYSQL docker run --name wordpress-mysql -p 3306:330 ...
- java的random生成某个范围内的随机数
import java.util.Random; /** * @author HP * @date 2019/4/16 */ public class randomTest { public stat ...
- python实践
https://www.cnblogs.com/smallSevens/p/10016045.html --二手房交易记录 https://www.cnblogs.com/xiangyuecn/p/1 ...
- Centos 自动删除日志文件的Shell代码
#!/bin/bash # #判断文件夹内文件的大小,如果大于一定的数值,那么删除 # echo '判断文件夹内文件的大小,如果大于一定的数值,并且文件名称包含数字(年月日)的删除,那么删除' pat ...
- 九九乘法表---for循环的嵌套
package com.zuoye.test;//控制台输出九九乘法表public class Jiujiu { public static void main(String[] args) { in ...
- WEB笔记-5、字体和文本
字体样式 font-family font-size font-weight font-style font-variant font(简写) 常用字体: serif,衬线字体,每个字符笔画末端会有装 ...
- C#如何判断操作系统语言版本
using System.Runtime.InteropServices; static void Main(string[] args) { System.Console.WriteLine(Sys ...