bitch bitch bitch...

TLE,WA一大坨,我是在拿生命来JUDGE啊。。

不得不说,UVA上的数据根本不是随机的,而是有预谋的。

for(int i=2;i<n;i++){
  while(stop>1&&cross(p[i],p[st[stop-1]],p[st[stop-2]])>=0) stop--;   //这个我本来是cross(p[i],p[st[stop-1]],p[st[stop-2]])>0
  st[stop++]=i;
}

因为没加上一个“=”号,就把边上所有共线的点都搞上了,之后,由于N太大,无可奈何的TLE、WA了。呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵吕森哥哥哥哥哥可可

算法如下:

  1. 计算全部四个多边形的端点, 称之为 xminP, xmaxP, yminP, ymaxP。
  2. 通过四个点构造 P 的四条切线。 他们确定了两个“卡壳”集合。
  3. 如果一条(或两条)线与一条边重合, 那么计算由四条线决定的矩形的面积, 并且保存为当前最小值。 否则将当前最小值定义为无穷大。
  4. 顺时针旋转线直到其中一条和多边形的一条边重合。
  5. 计算新矩形的面积, 并且和当前最小值比较。 如果小于当前最小值则更新, 并保存确定最小值的矩形信息。
  6. 重复步骤4和步骤5, 直到线旋转过的角度大于90度。
  7. 输出外接矩形的最小面积。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define min(x,y) ((x)<(y)?(x):(y))
using namespace std; struct point
{
double x,y;
}p[1005]; int ans[1005],st[1005],stop,cnt,n; int DB (double d){
if (fabs(d)<1e-8)
return 0;
return d>0?1:-1;
}
double cross (point a,point b,point c){
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
double dot(point a,point b,point c){
return (a.x-c.x)*(b.x-c.x)+(a.y-c.y)*(b.y-c.y);
}
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;
} void forTU(){
stop=cnt=0;
st[stop++]=0; st[stop++]=1;
for(int i=2;i<n;i++){
while(stop>1&&cross(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&&cross(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 roating(){
cnt--;
if(n<3) return 0;
int i,m=1,q=1,r;
double anst=1e10,a,b,c;
for(i=0;i<cnt;i++){
while (DB(cross(p[ans[(i+1)]],p[ans[(m+1)]],p[ans[i]])-cross(p[ans[(i+1)]],p[ans[m]],p[ans[i]])) >0)
m=(m+1)%cnt;
while (DB(dot(p[ans[(q+1)]],p[ans[(i+1)]],p[ans[i]])-dot(p[ans[q]],p[ans[(i+1)]],p[ans[i]])) >0)
q=(q+1)%cnt;
if (i==0)
r=q;
while(DB(dot(p[ans[(r+1)]],p[ans[(i+1)]],p[ans[i]])-dot(p[ans[r]],p[ans[(i+1)]],p[ans[i]])) <= 0)
r=(r+1)%cnt;
a=cross(p[ans[(i+1)]],p[ans[m]],p[ans[i]]);
b=dot(p[ans[q]],p[ans[(i+1)]],p[ans[i]])-dot(p[ans[r]],p[ans[(i+1)]],p[ans[i]]);
c=dot(p[ans[(i+1)]],p[ans[(i+1)]],p[ans[i]]);
anst=min(anst,a*b/c);
}
return anst;
} int main (){
while (scanf("%d",&n) && n!=0) {
for (int i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmp);
forTU();
printf("%.4lf\n",roating());
}
return 0;
}

  

最新文章

  1. c语言中,既然不支持函数重载,那么printf算怎么回事?在c语言中,它不就是被重载了吗?
  2. 存储过程优点&amp;缺点
  3. 整数划分 Integer Partition(二)
  4. 原生JS修改标签样式为带阴影效果
  5. swift和 oc 混编2-备
  6. 转:Gulp的目标是取代Grunt
  7. tju_4147 kd树+最小生成树
  8. 安卓微信连接fiddler等抓包工具无法抓取https
  9. 使用nginx代理kibana并配置登录验证
  10. linux命令-crontab
  11. Unity 3D动态修改Shader状态,使物体透明等等
  12. c# winform+wcf代理上网的处理
  13. css-深入理解margin和padding
  14. 同一个IP段ping不通同事的电脑
  15. NET 时间字符串转换
  16. windows 下搭建git服务器,及问题处理。
  17. EDB*Plus的client_encoding问题
  18. qt中int与string的相互转换
  19. 常用JS、jquery 命令(不断更新中)
  20. L152

热门文章

  1. Android中使用Gson解析JSON数据
  2. bzoj 3172 单词
  3. Winform 异步调用
  4. [转]RDLC 动态列
  5. 题解报告:hdu 1848 Fibonacci again and again(尼姆博弈)
  6. C - Alice, Bob and Chocolate(贪心)
  7. Windows phone开发之文件夹与文件操作系列(一)文件夹与文件操作
  8. angular js 球星
  9. 努比亚(nubia) V18 NX612J 解锁BootLoader 并刷入recovery ROOT
  10. Deutsch lernen (03)