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;
}

  

UVA 10173的更多相关文章

  1. UVA 10173 (几何凸包)

    判断矩形能包围点集的最小面积:凸包 #include <iostream> #include <cmath> #include <cstdio> #include ...

  2. 此坑待填 离散化思想和凸包 UVA - 10173 Smallest Bounding Rectangle

    Smallest Bounding Rectangle Given the Cartesian coordinates of n(>0)2-dimensional points, write a ...

  3. hdu3982 直线切多边形 【WA中...】

    题意:有一块蛋糕,上面有一颗cherry.用刀子切n次,求切完之后有cherry的那部分的面积 My solution: 先做一个大矩形,使cake内切于这个大矩形.如图: 然后不断切这个大矩形,每次 ...

  4. 【kuangbin】计算几何部分最新模板

    二维几何部分 // `计算几何模板` ; const double inf = 1e20; const double pi = acos(-1.0); ; //`Compares a double t ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. DCloud-MUI:utils

    ylbtech-DCloud-MUI:utils 1.返回顶部 1.init mui框架将很多功能配置都集中在mui.init方法中,要使用某项功能,只需要在mui.init方法中完成对应参数配置即可 ...

  2. 排序系列 之 归并排序算法 —— Java实现

    基本思想: 归并排序法是分治法的典型实例,分为分割和归并两部分. 把一个数组分为大小相近的子数组(分割),分别把子数组排好序后,通过合成一个大的排好序的数组(归并). 实例: 先分割成每个子序列只有一 ...

  3. bzoj1708[Usaco2007 Oct]Money奶牛的硬币(背包方案数dp)

    1708: [Usaco2007 Oct]Money奶牛的硬币 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 763  Solved: 511[Submi ...

  4. collectionView必须点击两次才跳转

    今天遇到一个很奇怪的现象:collectionView必须点击两次才能跳转.具体看代码: -(void)collectionView:(UICollectionView *)collectionVie ...

  5. (转)JavaScript深入之从原型到原型链

    构造函数创建对象 我们先使用构造函数创建一个对象: function Person() { } var person = new Person(); person.name = 'Kevin'; co ...

  6. oracle从入门到精通复习笔记

    为方便大家跟着我的笔记练习,为此提供数据库表文件给大家下载:点我下载 描述一个表用 desc employees过滤重复的部门 select distinct department_id from e ...

  7. MatLab之HDL coder

    1 Workflow The workflow for applying HDL code generation to the hardware design process requires the ...

  8. Windows下VS2013 C++编译测试faster-rcnn

    [原创帖!转载请注明出处:http://www.cnblogs.com/LaplaceAkuir/p/6445189.html] 本人最近研究faster-rcnn,在ubuntu成功跑通matlab ...

  9. trait 和abstract的区别在哪里

    无法在一个class上extend多个abstract class,但是你可以use多个trait abstract class是在类型系统上做文章,trait片段是mixin 类型约束 代码复用 c ...

  10. js 验证文件格式和大小

    <script> $('#btnSearch').click(function(){ // alert("000");// fileElem = document.ge ...