BZOJ 1069 Luogu P4166 最大土地面积 (凸包)
题目链接: (bzoj)https://www.lydsy.com/JudgeOnline/problem.php?id=1069
(luogu)https://www.luogu.org/problemnew/show/P4166
题解: 水题,凸包极角排序之后枚举凸四边形对角线\(i,j\)然后找面积最大的点\(k\),\(k\)随着\(i,j\)是单调的
但是有个易错点,就是双指针那个\(k\)前移的条件必须是前移后大于等于原来,如果写成大于就只有50(详见代码)
查了半天发现原因居然是: 数据里有重点! 一旦有重点就会出现\(k\)一直在重点处进不动的情况。呜呜呜好坑啊
代码
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<algorithm>
#include<cmath>
using namespace std;
const double EPS = 1e-8;
int dcmp(double x) {return x<-EPS ? -1 : (x>EPS ? 1 : 0);}
struct Point
{
double x,y;
Point() {}
Point(double _x,double _y) {x = _x,y = _y;}
};
bool cmpy(Point x,Point y) {return dcmp(x.y-y.y)<0 || (dcmp(x.y-y.y)==0 && dcmp(x.x-y.x)<0);}
bool cmpx(Point x,Point y) {return dcmp(x.x-y.x)<0 || (dcmp(x.x-y.x)==0 && dcmp(x.y-y.y)<0);}
typedef Point Vector;
Point operator +(Point x,Point y) {return Point(x.x+y.x,x.y+y.y);}
Point operator -(Point x,Point y) {return Point(x.x-y.x,x.y-y.y);}
Point operator *(Point x,double y) {return Point(x.x*y,x.y*y);}
Point operator /(Point x,double y) {return Point(x.x/y,x.y/y);}
double Dot(Vector x,Vector y) {return x.x*y.x+x.y*y.y;}
double Cross(Vector x,Vector y) {return x.x*y.y-x.y*y.x;}
double EuclidDist(Point x,Point y) {return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}
Vector rotate(Vector x,double ang) {return Vector(x.x*cos(ang)-x.y*sin(ang),x.x*sin(ang)+x.y*cos(ang));}
const int N = 2000;
Point a[N+3];
Point ch[(N<<1)+3];
int stk[N+3];
double area[N+3][N+3];
int n,tp;
bool cmp(Point x,Point y) {return dcmp(Cross(x-a[1],y-a[1]))>0;}
void Convex_Hull()
{
for(int i=2; i<=n; i++)
{
if(cmpy(a[i],a[1])==true) {swap(a[i],a[1]);}
}
sort(a+2,a+n+1,cmp);
stk[1] = 1; stk[2] = 2; tp = 2;
for(int i=3; i<=n; i++)
{
while(dcmp(Cross(a[i]-a[stk[tp-1]],a[stk[tp]]-a[stk[tp-1]]))>0) {tp--;}
tp++; stk[tp] = i;
}
for(int i=1; i<=tp; i++) ch[i] = a[stk[i]];
for(int i=1; i<=tp; i++) ch[i+tp] = ch[i];
// printf("chsize=%d\n",tp);
// for(int i=1; i<=tp; i++) printf("(%lf %lf)\n",ch[i].x,ch[i].y);
}
int main()
{
scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%lf%lf",&a[i].x,&a[i].y);
Convex_Hull();
if(tp==3)
{
double ans = fabs(Cross(ch[2]-ch[1],ch[3]-ch[1]))/2.0,ans2 = 1e11;
for(int i=1; i<=n; i++)
{
if(i==stk[1]||i==stk[2]||i==stk[3]) continue;
double cur = min(min(fabs(Cross(a[i]-ch[1],ch[2]-ch[1])),fabs(Cross(a[i]-ch[2],ch[3]-ch[2]))),fabs(Cross(a[i]-ch[3],ch[1]-ch[3])))/2.0;
ans2 = min(ans2,cur);
}
printf("%lf\n",ans-ans2);
return 0;
}
double ans = 0.0;
for(int i=1; i<=tp; i++)
{
int k = i+1;
for(int j=i+2; j<=i+tp-2; j++)
{
while(k+1<j && dcmp(Cross(ch[k+1]-ch[i],ch[j]-ch[i])-Cross(ch[k]-ch[i],ch[j]-ch[i]))>=0) {k++;}
area[i][(j-1)%tp+1] = Cross(ch[k]-ch[i],ch[j]-ch[i])/2.0;
// printf("i%d j%d k%d %lf\n",i,j,k,area[j]);
}
}
for(int i=1; i<=tp; i++)
{
for(int j=i+2; j<=tp; j++)
{
double tmp = area[i][j]+area[j][i];
// printf("area[%d][%d]=%lf\n",i,j,area[i][j]);
// printf("area[%d][%d]=%lf\n",j,i,area[j][i]);
ans = max(ans,tmp);
}
}
printf("%.3lf\n",ans);
return 0;
}
BZOJ 1069 Luogu P4166 最大土地面积 (凸包)的更多相关文章
- ●BZOJ 1069 [SCOI2007]最大土地面积
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1069 题解: 计算几何,凸包,旋转卡壳 其实和这个题差不多,POJ 2079 Triangl ...
- BZOJ 3052/Luogu P4074 [wc2013]糖果公园 (树上带修莫队)
题面 中文题面,难得解释了 BZOJ传送门 Luogu传送门 分析 树上带修莫队板子题... 开始没给分块大小赋初值T了好一会... CODE #include <bits/stdc++.h&g ...
- BZOJ 3931 / Luogu P3171 [CQOI2015]网络吞吐量 (最大流板题)
题面 中文题目,不解释: BZOJ传送门 Luogu传送门 分析 这题建图是显然的,拆点后iii和i′i'i′连容量为吞吐量的边,根据题目要求,111和nnn的吞吐量看作∞\infty∞. 然后用di ...
- BZOJ 3894 / Luogu P4313 文理分科 (拆点最小割)
题面 中文题面- BZOJ 传送门 Luogu 传送门 分析 这道题类似于BZOJ 3774 最优选择,然后这里有一篇博客写的很好- Today_Blue_Rainbow's Blog 应该看懂了吧- ...
- BZOJ 2039 / Luogu P1791 [2009国家集训队]employ人员雇佣 (最小割)
题面 BZOJ传送门 Luogu传送门 分析 考虑如何最小割建图,因为这仍然是二元关系,我们可以通过解方程来确定怎么建图,具体参考论文 <<浅析一类最小割问题 湖南师大附中 彭天翼> ...
- BZOJ 2127 / Luogu P1646 [国家集训队]happiness (最小割)
题面 BZOJ传送门 Luogu传送门 分析 这道题又出现了二元关系,于是我们只需要解方程确定怎么连边就行了 假设跟SSS分在一块是选文科,跟TTT分在一块是选理科,先加上所有的收益,再来考虑如何让需 ...
- [BZOJ 1535] [Luogu 3426]SZA-Template (KMP+fail树+双向链表)
[BZOJ 1535] [Luogu 3426]SZA-Template (KMP+fail树+双向链表) 题面 Byteasar 想在墙上涂一段很长的字符,他为了做这件事从字符的前面一段中截取了一段 ...
- [BZOJ 3295] [luogu 3157] [CQOI2011]动态逆序对(树状数组套权值线段树)
[BZOJ 3295] [luogu 3157] [CQOI2011] 动态逆序对 (树状数组套权值线段树) 题面 给出一个长度为n的排列,每次操作删除一个数,求每次操作前排列逆序对的个数 分析 每次 ...
- [BZOJ 3110] [luogu 3332] [ZJOI 2013]k大数查询(权值线段树套线段树)
[BZOJ 3110] [luogu 3332] [ZJOI 2013]k大数查询(权值线段树套线段树) 题面 原题面有点歧义,不过从样例可以看出来真正的意思 有n个位置,每个位置可以看做一个集合. ...
随机推荐
- 利用ansible进行主机信息收集
--- - hosts: myjob gather_facts: True vars: IP: "{{ ansible_default_ipv4['address'] }}" HO ...
- 推荐几本Python书
Python的书很多,由于python本身应用的领域太多,涉及方方面面的,因此书籍的种类也很多,下面是我推荐一些比较好的python书给大家,大家可以找一两本修炼,定能让你的功力大增. 1.A byt ...
- Exchange 2010的部署
实验拓扑: 实验准备条件:计算机基本配置的准备:DC (vbers):配置IP地址.子网掩码.网关EX (vbers2):配置IP地址.子网掩码.网关.指定DNS 域环境搭建的准备1.在计算机名为vb ...
- loj 2778「BalticOI 2018」基因工程
loj luogu 这题和NOI那道向量内积一个套路 首先考虑求两行的不同元素个数,可以转化成一个行向量\(a\)和列向量\(b\)相乘得到一个值.如果只有\(A,C\)两种字符,那么令对应权值\(A ...
- MySQL数据库入门常用基础命令
MySQL数据库入门———常用基础命令 数据——公司的生命线,因此在大多数的互联网公司,都在使用开源的数据库产品,MySQL也因此关注度与使用率非常的高,所以做为运维的屌丝们,掌握它的一些基 ...
- node.js中使用imagemagick进行图片裁剪压缩
node.js中使用imagemagick进行图片裁剪压缩 安装imagemagick sudo apt-get install imagemagick or wget http://www.imag ...
- setTimeout定时器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- multipart/form-data提交
pip install requests-toolbelt from requests_toolbelt import MultipartEncoder import requests m = Mul ...
- error: (-215) !empty() in function detectMultiScale
tips: pip install opencv-python or https://www.lfd.uci.edu/~gohlke/pythonlibs/ 原因确实是找不到 opencv 的 xml ...
- linux 下 SpiderMonkey 1.7.0 编译和安装
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz tar xf js-1.7.0.tar.gz cd js/src make ...