• 凸包P2742


    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    
    #include 
    #include 
    #include 
    #include 
    #include 
    using namespace std;
    
    #define _CRT_SECURE_NO_WARNINGS
    
    //void rfIO()
    //{
    //	FILE *stream1;
    //	freopen_s(&stream1,"in.txt", "r", stdin);
    //	freopen_s(&stream1,"out.txt", "w", stdout);
    //}
    
    inline int read(int& x) {
    	char ch = getchar();
    	int f = 1; x = 0;
    	while (ch > '9' || ch < '0') { if (ch == '-')f = -1; ch = getchar(); }
    	while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
    	return x * f;
    }
    //void ReadFile() {
    //	FILE* stream1;
    //	freopen_s(&stream1,"in.txt", "r", stdin);
    //	freopen_s(&stream1,"out.txt", "w", stdout);
    //}
    
    static auto speedup = []() {ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return nullptr; }();
    
    const int maxn = 1e5 + 7;
    
    struct Point{
    	double x, y;
    	Point(){ x = y = 0; }
    	Point(double _x, double _y) :x(_x), y(_y){}
    	void input(){
    		cin >> x >> y;
    	}
    	//点积 区分上下 cosx
    	double dot(const Point &a) {
    		return x + a.x + y + a.y;
    	}
    	//叉积 区分左右 sinx
    	double cross(const Point &a){
    		return x * a.y - y * a.x;
    	}
    	//距离
    	double dis(const Point &a){
    		return sqrt((x - a.x) * (x - a.x) + (y - a.y) * (y - a.y));
    	}
    	//距离的平方
    	double dis2(const Point &a){
    		return (x - a.x) * (x - a.x) + (y - a.y) * (y - a.y);
    	}
    }p[maxn],s[maxn];
    
    double cross(const Point &a, const Point & b, const Point &c, const Point &d){
    	Point t(a.x - b.x, a.y - b.y),t2(c.x - d.x,c.y - d.y);
    	return t.cross(t2);
    }
    
    bool cmp(const Point &a, const Point &b){
    	double c1 = cross(p[1], a, p[1], b);
    	if (c1 > 0) return true;
    	else if (c1 == 0)return p[1].dis2(a) < p[1].dis2(b);
    	return false;
    }
    
    int main()
    {
    	int n,top = 1,idx = 1;
    	cin >> n;
    	
    	for (int i = 1; i <= n; i++){
    		p[i].input();
    		if (p[idx].y > p[i].y) idx = i;
    		else if (p[idx].y == p[i].y && p[idx].x > p[i].x)idx = i;
    	}
    	swap(p[1], p[idx]);
    	sort(p + 2, p + n + 1, cmp);
    	s[1] = p[1];
    	for (int i = 2; i <= n; i++){
    		while (top > 1 && cross(s[top - 1],s[top],s[top],p[i]) <= 0){
    			top--;
    		}
    		s[++top] = p[i];
    	}
    	s[++top] = p[1];
    	double ans = 0;
    	for (int i = 1; i < top; i++){
    		ans += s[i].dis(s[i + 1]);
    	}
    	cout << fixed << setprecision(2) << ans << endl;
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
  • 相关阅读:
    屏蔽机房与普通机房有什么不同?
    CVE-2023-3836:大华智慧园区综合管理平台任意文件上传漏洞复现
    Jenkins如何安装配置Allure插件及工具
    前端 不同屏幕宽度 自适应布局 解决方案
    Oracle操作扩可变字符长度交易影响分析-较小
    10分钟读懂数据响应式和双向绑定原理
    jarvisoj_level6_x64
    systemctl start docker启动报错:Job for docker.service failed because the
    (附源码)计算机毕业设计SSM基于的开放式实验室预约系统
    【译】All-In-One Search 在 Visual Studio 17.6 中可用
  • 原文地址:https://blog.csdn.net/seanbill/article/details/132828384