题目链接: (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\)一直在重点处进不动的情况。呜呜呜好坑啊

代码

  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<cassert>
  5. #include<algorithm>
  6. #include<cmath>
  7. using namespace std;
  8. const double EPS = 1e-8;
  9. int dcmp(double x) {return x<-EPS ? -1 : (x>EPS ? 1 : 0);}
  10. struct Point
  11. {
  12. double x,y;
  13. Point() {}
  14. Point(double _x,double _y) {x = _x,y = _y;}
  15. };
  16. 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);}
  17. 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);}
  18. typedef Point Vector;
  19. Point operator +(Point x,Point y) {return Point(x.x+y.x,x.y+y.y);}
  20. Point operator -(Point x,Point y) {return Point(x.x-y.x,x.y-y.y);}
  21. Point operator *(Point x,double y) {return Point(x.x*y,x.y*y);}
  22. Point operator /(Point x,double y) {return Point(x.x/y,x.y/y);}
  23. double Dot(Vector x,Vector y) {return x.x*y.x+x.y*y.y;}
  24. double Cross(Vector x,Vector y) {return x.x*y.y-x.y*y.x;}
  25. double EuclidDist(Point x,Point y) {return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));}
  26. Vector rotate(Vector x,double ang) {return Vector(x.x*cos(ang)-x.y*sin(ang),x.x*sin(ang)+x.y*cos(ang));}
  27. const int N = 2000;
  28. Point a[N+3];
  29. Point ch[(N<<1)+3];
  30. int stk[N+3];
  31. double area[N+3][N+3];
  32. int n,tp;
  33. bool cmp(Point x,Point y) {return dcmp(Cross(x-a[1],y-a[1]))>0;}
  34. void Convex_Hull()
  35. {
  36. for(int i=2; i<=n; i++)
  37. {
  38. if(cmpy(a[i],a[1])==true) {swap(a[i],a[1]);}
  39. }
  40. sort(a+2,a+n+1,cmp);
  41. stk[1] = 1; stk[2] = 2; tp = 2;
  42. for(int i=3; i<=n; i++)
  43. {
  44. while(dcmp(Cross(a[i]-a[stk[tp-1]],a[stk[tp]]-a[stk[tp-1]]))>0) {tp--;}
  45. tp++; stk[tp] = i;
  46. }
  47. for(int i=1; i<=tp; i++) ch[i] = a[stk[i]];
  48. for(int i=1; i<=tp; i++) ch[i+tp] = ch[i];
  49. // printf("chsize=%d\n",tp);
  50. // for(int i=1; i<=tp; i++) printf("(%lf %lf)\n",ch[i].x,ch[i].y);
  51. }
  52. int main()
  53. {
  54. scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%lf%lf",&a[i].x,&a[i].y);
  55. Convex_Hull();
  56. if(tp==3)
  57. {
  58. double ans = fabs(Cross(ch[2]-ch[1],ch[3]-ch[1]))/2.0,ans2 = 1e11;
  59. for(int i=1; i<=n; i++)
  60. {
  61. if(i==stk[1]||i==stk[2]||i==stk[3]) continue;
  62. 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;
  63. ans2 = min(ans2,cur);
  64. }
  65. printf("%lf\n",ans-ans2);
  66. return 0;
  67. }
  68. double ans = 0.0;
  69. for(int i=1; i<=tp; i++)
  70. {
  71. int k = i+1;
  72. for(int j=i+2; j<=i+tp-2; j++)
  73. {
  74. 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++;}
  75. area[i][(j-1)%tp+1] = Cross(ch[k]-ch[i],ch[j]-ch[i])/2.0;
  76. // printf("i%d j%d k%d %lf\n",i,j,k,area[j]);
  77. }
  78. }
  79. for(int i=1; i<=tp; i++)
  80. {
  81. for(int j=i+2; j<=tp; j++)
  82. {
  83. double tmp = area[i][j]+area[j][i];
  84. // printf("area[%d][%d]=%lf\n",i,j,area[i][j]);
  85. // printf("area[%d][%d]=%lf\n",j,i,area[j][i]);
  86. ans = max(ans,tmp);
  87. }
  88. }
  89. printf("%.3lf\n",ans);
  90. return 0;
  91. }

BZOJ 1069 Luogu P4166 最大土地面积 (凸包)的更多相关文章

  1. ●BZOJ 1069 [SCOI2007]最大土地面积

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1069 题解: 计算几何,凸包,旋转卡壳 其实和这个题差不多,POJ 2079 Triangl ...

  2. BZOJ 3052/Luogu P4074 [wc2013]糖果公园 (树上带修莫队)

    题面 中文题面,难得解释了 BZOJ传送门 Luogu传送门 分析 树上带修莫队板子题... 开始没给分块大小赋初值T了好一会... CODE #include <bits/stdc++.h&g ...

  3. BZOJ 3931 / Luogu P3171 [CQOI2015]网络吞吐量 (最大流板题)

    题面 中文题目,不解释: BZOJ传送门 Luogu传送门 分析 这题建图是显然的,拆点后iii和i′i'i′连容量为吞吐量的边,根据题目要求,111和nnn的吞吐量看作∞\infty∞. 然后用di ...

  4. BZOJ 3894 / Luogu P4313 文理分科 (拆点最小割)

    题面 中文题面- BZOJ 传送门 Luogu 传送门 分析 这道题类似于BZOJ 3774 最优选择,然后这里有一篇博客写的很好- Today_Blue_Rainbow's Blog 应该看懂了吧- ...

  5. BZOJ 2039 / Luogu P1791 [2009国家集训队]employ人员雇佣 (最小割)

    题面 BZOJ传送门 Luogu传送门 分析 考虑如何最小割建图,因为这仍然是二元关系,我们可以通过解方程来确定怎么建图,具体参考论文 <<浅析一类最小割问题 湖南师大附中 彭天翼> ...

  6. BZOJ 2127 / Luogu P1646 [国家集训队]happiness (最小割)

    题面 BZOJ传送门 Luogu传送门 分析 这道题又出现了二元关系,于是我们只需要解方程确定怎么连边就行了 假设跟SSS分在一块是选文科,跟TTT分在一块是选理科,先加上所有的收益,再来考虑如何让需 ...

  7. [BZOJ 1535] [Luogu 3426]SZA-Template (KMP+fail树+双向链表)

    [BZOJ 1535] [Luogu 3426]SZA-Template (KMP+fail树+双向链表) 题面 Byteasar 想在墙上涂一段很长的字符,他为了做这件事从字符的前面一段中截取了一段 ...

  8. [BZOJ 3295] [luogu 3157] [CQOI2011]动态逆序对(树状数组套权值线段树)

    [BZOJ 3295] [luogu 3157] [CQOI2011] 动态逆序对 (树状数组套权值线段树) 题面 给出一个长度为n的排列,每次操作删除一个数,求每次操作前排列逆序对的个数 分析 每次 ...

  9. [BZOJ 3110] [luogu 3332] [ZJOI 2013]k大数查询(权值线段树套线段树)

    [BZOJ 3110] [luogu 3332] [ZJOI 2013]k大数查询(权值线段树套线段树) 题面 原题面有点歧义,不过从样例可以看出来真正的意思 有n个位置,每个位置可以看做一个集合. ...

随机推荐

  1. Leetcode 38.报数 By Python

    报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 被读作 "one 1" ...

  2. 字典树(trie树) 后缀树 广义后缀树

    转自:http://www.cnblogs.com/dong008259/archive/2011/11/11/2244900.html (1)字典树(Trie树) Trie是个简单但实用的数据结构, ...

  3. Springboot2.0加载指定配置文件@PropertySource的使用

    1. 在resouces下编写待加载的配置文件 这里使用person.properties # String person.last-name=john # int person.age=112 # ...

  4. [LeetCode] 227. 基本计算器 II

    题目链接: https://leetcode-cn.com/problems/basic-calculator-ii 难度:中等 通过率:33.2% 题目描述: 实现一个基本的计算器来计算一个简单的字 ...

  5. Android 开源项目及库汇总(2)

    Android 开源项目及库汇总(2) ListenToCode 2.7 2018.10.10 15:43 字数 8527 阅读 1001评论 0喜欢 29 地图 百度地图– Android百度地图 ...

  6. 常用Java中response.setContentType参数

    image/bmp BMP image/png PNG image/gif GIF image/jpeg JPEG image/tiff TIFF image/x-dcx DCX image/x-pc ...

  7. KVM安装配置笔记

    系统环境centos6.6 一.KVM安装前系统相关操作: (1)修改内核模式为兼容内核启动 # grep -v "#" /etc/grub.confdevice (hd0) HD ...

  8. Linux中文件查找,压缩和打包指令

    1.文件的查找和搜索 可执行文件的搜索:which .whereis locate搜索文件 find搜索文件       1.1可执行文件的搜索       在Linux系统中,有成百上千个指令,不同 ...

  9. nginx的服务架构

    nginx服务架构 模块 习惯上将nginx的模块分成核心模块,HTTP模块,邮件模块,以及第三方模块 核心模块主要包含两类功能的支持,一类是主体功能,包括进程管理,权限管理错误日志解析,配置解析:另 ...

  10. windows2008R2下安装sqlserver2008R2时,点setup.exe应用程序无法打开错误代码0xc0150004

    windows2008R2下安装sqlserver2008R2时,点setup.exe应用程序无法打开错误代码0xc0150004 问题截图: 网上查的答案都是需要安装.net framework 3 ...