• LightOJ 1239


    LINK

    题意:类似POJ的宫殿围墙那道,只不过这道题数据稍微强了一点,有共线的情况

    思路:求凸包周长加一个圆周长

    /** @Date    : 2017-07-20 15:46:44
      * @FileName: LightOJ 1239 求凸包.cpp
      * @Platform: Windows
      * @Author  : Lweleth (SoungEarlf@gmail.com)
      * @Link    : https://github.com/
      * @Version : $Id$
      */
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <algorithm>
    #include <utility>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <stack>
    #include <queue>
    #include <math.h>
    //#include <bits/stdc++.h>
    #define LL long long
    #define PII pair<int ,int>
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    const double Pi = acos(-1.0);
    struct point
    {
    	double x, y;
    	point(){}
    	point(double _x, double _y){x = _x, y = _y;}
    	point operator -(const point &b) const
    	{
    		return point(x - b.x, y - b.y);
    	}
    	double operator *(const point &b) const 
    	{
    		return x * b.x + y * b.y;
    	}
    	double operator ^(const point &b) const
    	{
    		return x * b.y - y * b.x;
    	}
    };
    
    double xmult(point p1, point p2, point p0)  
    {  
        return (p1 - p0) ^ (p2 - p0);  
    }  
    
    double distc(point a, point b)
    {
    	return sqrt((double)((b - a) * (b - a)));
    }
    int sign(double x)
    {
    	if(fabs(x) < eps)
    		return 0;
    	if(x < 0)
    		return -1;
    	else 
    		return 1;
    }
    
    ////////
    int n;
    point stk[N];
    point p[N];
    
    int cmpC(point a, point b)//水平序排序
    {
    	return sign(a.x - b.x) < 0 || (sign(a.x - b.x) == 0 && sign(a.y - b.y) < 0);
    }
    
    int Graham(point *p, int n)//水平序
    {
    	sort(p, p + n, cmpC);
    	int top = 0;
    	for(int i = 0; i < n; i++)
    	{
    		while(top >= 2 && sign(xmult(stk[top - 2], stk[top - 1], p[i])) < 0)
    			top--;
    		stk[top++] = p[i];
    	}
    	int tmp = top;
    	for(int i = n - 2; i >= 0; i--)
    	{
    		while(top > tmp && sign(xmult(stk[top - 2],stk[top - 1] ,p[i] )) < 0)
    			top--;
    		stk[top++] = p[i];
    	}
    	if(n > 1)
    		top--;
    	return top;
    }
    
    int main()
    {
    	int T;
    	cin >> T;
    	int c = 0;
    	while(T--)
    	{
    		int n;
    		double l;
    		cin >> n >> l;
    		double x, y;
    		for(int i = 0; i < n; i++)
    		{
    			scanf("%lf%lf", &x, &y);
    			p[i] = point(x, y);
    		}
    		int m = Graham(p, n);
    		double ans = 2 * Pi * l;
    		stk[m++] = stk[0];//注意只有直线的情况
    		for(int i = 0; i < m - 1; i++)
    			ans += distc(stk[i], stk[i + 1]);
    		printf("Case %d: %.10lf
    ", ++c, ans);
    	}
        return 0;
    }
    
  • 相关阅读:
    总结一些关于操作数据库是sql语句还是存储过程问题
    vs2010 创建预编译头 Debug 正常 Release Link Error问题解决
    创建Unicode格式的INI文件
    dos命令记录以及dos下通过进程id查找工作路径
    windows下多字节和宽字节转换
    关于多字节传输导致的乱码问题
    关于mysql数据库字符集优先级问题
    转: Apache开启gzip
    HTML 5 drag and drop 简介
    转: ES6异步编程: co函数库的含义与用法
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7213788.html
Copyright © 2020-2023  润新知