题目链接

BZOJ1069

题解

首先四个点一定在凸包上

我们枚举对角线,剩下两个点分别是两侧最远的点

可以三分,复杂度\(O(n^2logn)\)

可以借鉴旋转卡壳的思想,那两个点随着对角线的一定单调不减,可以用两个指针维护,复杂度\(O(n^2)\)

  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdio>
  5. #include<cmath>
  6. #include<map>
  7. #define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
  8. #define REP(i,n) for (int i = 1; i <= (n); i++)
  9. #define mp(a,b) make_pair<int,int>(a,b)
  10. #define cls(s) memset(s,0,sizeof(s))
  11. #define cp pair<int,int>
  12. #define LL long long int
  13. using namespace std;
  14. const int maxn = 2005,maxm = 100005,INF = 1000000000;
  15. inline int read(){
  16. int out = 0,flag = 1; char c = getchar();
  17. while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
  18. while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
  19. return out * flag;
  20. }
  21. struct point{double x,y;}p[maxn],t[maxn];
  22. inline bool operator <(const point& a,const point& b){
  23. return a.x == b.x ? a.y < b.y : a.x < b.x;
  24. }
  25. inline point operator +(const point& a,const point& b){
  26. return (point){a.x + b.x,a.y + b.y};
  27. }
  28. inline point operator -(const point& a,const point& b){
  29. return (point){a.x - b.x,a.y - b.y};
  30. }
  31. inline double operator *(const point& a,const point& b){
  32. return a.x * b.x + a.y * b.y;
  33. }
  34. inline double cross(const point& a,const point& b){
  35. return a.x * b.y - a.y * b.x;
  36. }
  37. inline double dis(const point& a,const point& b){
  38. return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
  39. }
  40. inline double S(const point& a,const point& b,const point& c){
  41. return fabs(0.5 * cross(c - a,c - b));
  42. }
  43. int n,st[maxn],top;
  44. void cal(){
  45. sort(p + 1,p + 1 + n);
  46. st[top = 1] = 1;
  47. for (int i = 2; i <= n; i++){
  48. while (top > 1 && cross(p[i] - p[st[top]],p[st[top]] - p[st[top - 1]]) <= 0)
  49. top--;
  50. st[++top] = i;
  51. }
  52. int tmp = top;
  53. for (int i = n - 1; i; i--){
  54. while (top > tmp && cross(p[i] - p[st[top]],p[st[top]] - p[st[top - 1]]) <= 0)
  55. top--;
  56. st[++top] = i;
  57. }
  58. n = --top;
  59. for (int i = 1; i <= n; i++) t[i] = p[st[i]];
  60. for (int i = 1; i <= n; i++) p[i] = t[i];
  61. }
  62. void solve(){
  63. if (n == 3){printf("%.3lf",S(p[1],p[2],p[3])); return;}
  64. double ans = 0;
  65. for (int i = 1; i <= n - 3; i++){
  66. int x = i + 1,y = i + 3;
  67. for (int j = i + 3; j <= n; j++){
  68. if (S(p[i],p[i + 2],p[j]) > S(p[i],p[i + 2],p[y]))
  69. y = j;
  70. }
  71. ans = max(ans,S(p[i],p[i + 2],p[x]) + S(p[i],p[i + 2],p[y]));
  72. for (int j = i + 3; j <= n; j++){
  73. while (x + 1 < j && S(p[i],p[j],p[x + 1]) > S(p[i],p[j],p[x])) x++;
  74. while (y + 1 <= n && S(p[i],p[j],p[y + 1]) > S(p[i],p[j],p[y])) y++;
  75. ans = max(ans,S(p[i],p[j],p[x]) + S(p[i],p[j],p[y]));
  76. }
  77. }
  78. printf("%.3lf\n",ans);
  79. }
  80. int main(){
  81. n = read();
  82. if (n <= 2) {puts("0"); return 0;}
  83. REP(i,n) scanf("%lf%lf",&p[i].x,&p[i].y);
  84. cal();
  85. //REP(i,n) printf("(%lf,%lf)\n",p[i].x,p[i].y);
  86. solve();
  87. return 0;
  88. }

BZOJ1069 [SCOI2007]最大土地面积 【凸包 + 旋转卡壳】的更多相关文章

  1. bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积

    在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...

  2. [BZOJ1069][SCOI2007]最大土地面积 凸包+旋转卡壳

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 3669  Solved: 1451[Submit][Sta ...

  3. luogu P4166 [SCOI2007]最大土地面积 凸包 旋转卡壳

    LINK:最大土地面积 容易想到四边形的边在凸包上面 考虑暴力枚举凸包上的四个点计算面积. 不过可以想到可以直接枚举对角线的两个点找到再在两边各找一个点 这样复杂度为\(n^3\) 可以得到50分. ...

  4. bzoj 1069: [SCOI2007]最大土地面积 凸包+旋转卡壳

    题目大意: 二维平面有N个点,选择其中的任意四个点使这四个点围成的多边形面积最大 题解: 很容易发现这四个点一定在凸包上 所以我们枚举一条边再旋转卡壳确定另外的两个点即可 旋(xuan2)转(zhua ...

  5. BZOJ1069 SCOI2007 最大土地面积 凸包、旋转卡壳

    传送门 在这里假设可以选择两个相同的点吧-- 那么选出来的四个点一定会在凸包上 建立凸包,然后枚举这个四边形的对角线.策略是先枚举对角线上的一个点,然后沿着凸包枚举另一个点.在枚举另一个点的过程中可以 ...

  6. bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2277  Solved: 853[Submit][Stat ...

  7. 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳

    因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...

  8. [SCOI2007]最大土地面积(旋转卡壳)

    首先,最大四边形的四个点一定在凸包上 所以先求凸包 有个结论,若是随机数据,凸包包括的点大约是\(\log_2n\)个 然鹅,此题绝对不会这么轻松,若\(O(n^4)\)枚举,只有50分 所以还是要想 ...

  9. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  10. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

随机推荐

  1. phpcms 的模板更换

    刚安装完成后的phpcms ,自带的默认模板样式一般,可以自己换模板 首先打开phpcms文件夹,按照下图路径打开 default是存模板的文件夹 在里面新建一个文件夹 在default中主要用到的是 ...

  2. Python中的矩阵操作

    Numpy 通过观察Python的自有数据类型,我们可以发现Python原生并不提供多维数组的操作,那么为了处理矩阵,就需要使用第三方提供的相关的包. NumPy 是一个非常优秀的提供矩阵操作的包.N ...

  3. 用Micro:bit做剪刀、石头、布游戏

    剪刀.石头.布游戏大家都玩过,今天我们用Micro:bit建一个剪刀.石头.布游戏! 第一步,起始 当你摇动它时,我们希望the micro:bit选择剪刀.石头.布.尝试创建一个on shake b ...

  4. 「Leetcode」975. Odd Even Jump(Java)

    分析 注意到跳跃的方向是一致的,所以我们需要维护一个数接下来跳到哪里去的问题.换句话说,就是对于一个数\(A_i\),比它大的最小值\(A_j\)是谁?或者反过来. 这里有两种方案,一种是单调栈,简单 ...

  5. Http协议工作特点和工作原理笔记

    工作特点: (1)B/S结构(Browser/Server,浏览器/服务器模式) (2)无状态 (3)简单快速.可使用超文本传输协议.灵活运行传输各种类型 工作原理: 客户端发送请求浏览器 -> ...

  6. [network]RIP协议

    水平分割:一种避免路由环路的出现和加快路由汇聚的技术. 原理:路由器从某个接口接收到的更新信息不允许再从这个接口发送回去. 优点:1. 阻止路由环路产生:2. 减少路由器更新信息占用的链路带宽资源. ...

  7. Office 365 Powershell 连接命令

    国内版 第一步: Import-Module msonline Connect-MsolService 输入用户名密码 第二步: Get-MsolUser" 第三步: Set-Executi ...

  8. New begin

    Purpose 今天更换了id,希望重新沉淀. 晚上看到国外一个博客,落款有个中文: 敬惜字纸. 共勉.

  9. 第八次ScrumMeeting博客

    第八次ScrumMeeting博客 本次会议于11月2日(四)22时整在3公寓725房间召开,持续20分钟. 与会人员:刘畅.辛德泰.窦鑫泽.张安澜.赵奕.方科栋. 1. 每个人的工作(有Issue的 ...

  10. WEB前端开发流程总结

    作者声明:本博客中所写的文章,都是博主自学过程的笔记,参考了很多的学习资料,学习资料和笔记会注明出处,所有的内容都以交流学习为主.有不正确的地方,欢迎批评指正 WEB前端开发项目流程总结 1.新建项目 ...