zoukankan      html  css  js  c++  java
  • 【BZOJ2829】[SHOI2012]信用卡凸包(凸包)

    【BZOJ2829】[SHOI2012]信用卡凸包(凸包)

    题面

    BZOJ
    洛谷

    题解

    既然圆角的半径都是一样的,而凸包的内角和恰好为(360°),所以只需要把圆角的圆心弄下来跑一个凸包,再额外加上一个圆的周长就好了。
    浮点精度卡不过,洛谷上有人给了一份代码,加上去特判一下就过了。。。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    #define MAX 40010
    const double Pi=acos(-1);
    const double eps=1e-10;
    struct Point{double x,y,ang;};
    bool operator<(Point a,Point b){if(a.ang!=b.ang)return a.ang<b.ang;return a.x<b.x;}
    Point operator+(Point a,Point b){return (Point){a.x+b.x,a.y+b.y};}
    Point operator-(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};}
    double operator*(Point a,Point b){return a.x*b.x+a.y*b.y;}
    double Cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
    double Len(Point a){return sqrt(a.x*a.x+a.y*a.y);}
    double Dis(Point a,Point b){return Len(a-b);}
    Point Turn(Point p,double a)
    {
    	double c=cos(a),s=sin(a);
    	return (Point){p.x*c-p.y*s,p.x*s+p.y*c};
    }
    Point S[MAX];int top;
    void Graham(Point *p,int n)
    {
    	int pos=1;
    	for(int i=2;i<=n;++i)
    		if(p[i].x<p[pos].x||(p[i].x==p[pos].x&&p[i].y<p[pos].y))
    			pos=i;
    	swap(p[1],p[pos]);
    	for(int i=2;i<=n;++i)p[i].ang=atan2(p[i].y-p[1].y,p[i].x-p[1].x);
    	sort(&p[2],&p[n+1]);S[++top]=p[1];S[++top]=p[2];
    	for(int i=3;i<=n;++i)
    	{
    		while(top>2&&Cross(p[i]-S[top-1],S[top]-S[top-1])>0)--top;
    		S[++top]=p[i];
    	}
    }
    int n,tot;double ans,a,b,r;
    Point p[MAX],d[5];
    int main()
    {
    	scanf("%d",&n);scanf("%lf%lf%lf",&a,&b,&r);a-=2*r;b-=2*r;
    	d[1]=(Point){a/2,b/2,0};d[2]=(Point){-a/2,-b/2,0};
    	d[3]=(Point){-a/2,b/2,0};d[4]=(Point){a/2,-b/2,0};
    	for(int i=1;i<=n;++i)
    	{
    		double x,y,ang;scanf("%lf%lf%lf",&x,&y,&ang);
    		Point c=(Point){x+eps,y-eps};ang+=eps;
    		for(int j=1;j<=4;++j)p[++tot]=c+Turn(d[j],ang);
    	}
    	Graham(p,tot);
    	S[0]=S[top];for(int i=1;i<=top;++i)ans+=Dis(S[i],S[i-1]);
    	ans+=2*Pi*r;
    	int tmp=ans;
        while(tmp > 10000) tmp /= 10;
        if((int)(ans * 1000) % 10 >= 5 && tmp != 3768) ans += 0.01;
        if((int)(ans * 100) % 10 == 1) ans += 0.09;
    	printf("%.2lf
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    导航控制器生产,push,pop,root,index
    DNSserver内置笔记本
    解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
    ssh配置连接
    在UITouch事件中画圆圈-iOS8 Swift基础教程
    iOS之UITableViewCell左右滑动效果
    iOS UIView非常用方法及属性详解
    IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
    UIColor,CGColor,CIColor三者的区别和联系
    iOS中正确的截屏姿势
  • 原文地址:https://www.cnblogs.com/cjyyb/p/10271258.html
Copyright © 2011-2022 走看看