zoukankan      html  css  js  c++  java
  • 【bzoj2829】信用卡凸包 凸包

    题目描述

    输入

    输出

    样例输入

    2
    6.0 2.0 0.0
    0.0 0.0 0.0
    2.0 -2.0 1.5707963268

    样例输出

    21.66


    题解

    凸包

    傻逼题,答案显然为:所有圆心构成的凸包周长+一个圆的周长。这里求凸包用的方法是求上下两个凸壳再拼起来。

    时间复杂度为排序的 $O(nlog n)$ 

    我才不会告诉你puts("nan:)可以过呢

    #include <cmath>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    const double pi = acos(-1);
    struct data
    {
    	double x , y;
    	data() {}
    	data(double a , double b) {x = a , y = b;}
    	data operator-(const data &a)const {return data(x - a.x , y - a.y);}
    	double operator*(const data &a)const {return x * a.y - y * a.x;}
    	bool operator<(const data &a)const {return x == a.x ? y < a.y : x < a.x;}
    }p[40010] , sa[40010] , sb[40010];
    int ta , tb;
    inline double dis(data a , data b)
    {
    	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    }
    int main()
    {
    	int n , i , m = 0;
    	double a , b , r , x , y , c , ans = 0;
    	scanf("%d%lf%lf%lf" , &n , &a , &b , &r) , a = a / 2 - r , b = b / 2 - r;
    	for(i = 1 ; i <= n ; i ++ )
    	{
    		scanf("%lf%lf%lf" , &x , &y , &c);
    		p[++m] = data(x + b * cos(c) + a * sin(c) , y + b * sin(c) - a * cos(c));
    		p[++m] = data(x - b * cos(c) + a * sin(c) , y - b * sin(c) - a * cos(c));
    		p[++m] = data(x + b * cos(c) - a * sin(c) , y + b * sin(c) + a * cos(c));
    		p[++m] = data(x - b * cos(c) - a * sin(c) , y - b * sin(c) + a * cos(c));
    	}
    	sort(p + 1 , p + m + 1);
    	for(i = 1 ; i <= m ; i ++ )
    	{
    		while(ta > 1 && (p[i] - sa[ta]) * (sa[ta - 1] - sa[ta]) >= 0) ta -- ;
    		while(tb > 1 && (p[i] - sb[tb]) * (sb[tb - 1] - sb[tb]) <= 0) tb -- ;
    		sa[++ta] = sb[++tb] = p[i];
    	}
    	for(i = 1 ; i < ta ; i ++ ) ans += dis(sa[i] , sa[i + 1]);
    	for(i = 1 ; i < tb ; i ++ ) ans += dis(sb[i] , sb[i + 1]);
    	printf("%.2lf
    " , ans + dis(sa[1] , sb[1]) + dis(sa[ta] , sb[tb]) + 2 * pi * r);
    	return 0;
    }
    

     

  • 相关阅读:
    体验ASP.NET 2.0中的BuildProvider(转载)
    为什么要用非关系数据库?
    Inside ASP.NET 2.0即时编译系统(转载)
    文本信息检索(维基百科)
    通用数据压缩算法简介
    在HttpModule中使用gzip,deflate协议对aspx页面进行压缩
    NoSQL非关系型数据库
    fatal error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786)
    C++中的变量 Variables in C++
    Visual C++, pow(),error C2065: 'pow' : undeclared identifier
  • 原文地址:https://www.cnblogs.com/GXZlegend/p/8565265.html
Copyright © 2011-2022 走看看