zoukankan      html  css  js  c++  java
  • BZOJ 1113 Wall ——计算几何

    凸包第一题。

    自己认为自己写的是Andrew

    其实就是xjb写出来居然过掉了测试。

    刚开始把pi定义成了int,调了半天

    #include <map>
    #include <cmath>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define F(i,j,k) for (int i=j;i<=k;++i)
    #define D(i,j,k) for (int i=j;i>=k;--i)
    #define eps 1e-10
    #define ll long long
    #define mp make_pair
    
    const double pi=acos(-1.0);
    
    struct Vector{
    	double x,y;
    	void print()
    	{
    		printf("Vector - > (%.3f,%.3f)
    ",x,y);
    	}
    };
    struct Point{
    	double x,y;
    	void print()
    	{
    		printf("Point - > (%.3f,%.3f)
    ",x,y);
    	}
    };
    
    double operator * (Vector a,Vector b)
    {return a.x*b.y-a.y*b.x;}
    
    Vector operator + (Vector a,Vector b)
    {Vector ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;}
    
    Vector operator - (Vector a,Vector b)
    {Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;}
    
    Point operator + (Point a,Vector b)
    {Point ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;}
    
    Vector operator * (Vector a,double b)
    {Vector ret;ret.x=a.x*b;ret.y=a.y*b;return ret;}
    
    Vector operator - (Point a,Point b)
    {Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;}
    
    double dot (Vector a,Vector b)
    {return a.x*b.x+a.y*b.y;}
    
    double len(Vector a)
    {return sqrt(dot(a,a));}
    
    int n,l,top,sta[1005];
    
    Point a[1005];
    
    bool cmp(Point a,Point b)
    {return fabs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;}
    
    int main()
    {
    	scanf("%d%d",&n,&l);
    	F(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
    	sort(a+1,a+n+1,cmp);
    	sta[++top]=1;
    	F(i,2,n)
    	{
    		while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
    		sta[++top]=i;
    	}
    	D(i,n-1,1)
    	{
    		while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
    		sta[++top]=i;
    	}
    	double ans=0;
    	F(i,2,top)
    	{
    		ans+=len(a[sta[i]]-a[sta[i-1]]);
    //		(a[sta[i]]-a[sta[i-1]]).print();
    	}
    	ans+=2.0*l*pi;
    //	printf("%.6f
    ",pi);
    //	printf("%.6f
    ",2.0*l*pi);
    	printf("%d
    ",(int)(ans+0.5));
    }
    

      

  • 相关阅读:
    CSS3新增文本属性实现图片点击切换效果
    swipe和swiper的区别
    uncaught syntaxerror: unexpected token
    科协前辈的阿里面试经验转载1
    Oracle 分析函数
    Jakarta Commons HttpClient 学习笔记 (二)
    Ubuntu eclipse下android virtual device manager不能删除AVD
    Android的界面设计工具——DroidDraw
    JS异步请求数据
    Ubuntu配置JDK和Android环境变量
  • 原文地址:https://www.cnblogs.com/SfailSth/p/6687354.html
Copyright © 2011-2022 走看看