POJ 1113

22 篇文章 0 订阅
2 篇文章 0 订阅

我有白痴了原来强制类型转换不会自动四舍五入只会保留整数部分,,,,,好吧我是白痴


#include <iostream>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>


using namespace std;
#define MAXN 1111
#define PI 3.1415926


struct Point
{
    double x, y;
    double len;
}p[MAXN] , sta[MAXN], p0;
int top = 2;
double getdis(Point a, Point b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}


double Across(Point a, Point b, Point c)
{
     return (b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x);
}


bool cmp(Point a, Point b )
{
    double k = Across(p0, a, b);
    if(k > 0) return true;
    if(k < 0) return false;
    a.len = getdis(p0,a);
    b.len = getdis(p0,b);
    return a.len < b.len;
}


void Findp0( int n)
{
    p0 = p[1];
    int pos = 1;
    for(int i = 2; i <= n; i++)
    {
        if(p0.y > p[i].y || (p0.y == p[i].y && p0.x > p[i].x))
        {
            pos = i;
            p0 = p[i];
        }
    }
    swap(p[1], p[pos]);
}


void Graham( int n)
{
    sta[1] = p[1];
    sta[2] = p[2];


    for(int i = 3; i <= n; i++)
    {
        while(Across(sta[top-1],sta[top], p[i]) < 0 && top > 1) top--;
        sta[++top] = p[i];
    }
}


int main()
{
    int n, l;
    while(scanf("%d %d",&n ,&l) != EOF)
    {
        top = 2;
        for(int i = 1; i <= n; i++)
          scanf("%lf %lf",&p[i].x, &p[i].y);
        Findp0(n);
        sort(p+1, p + 1 + n, cmp);
        Graham(n);
        double ans = 0;


       for(int i = 1; i < top; i++)
          ans += getdis(sta[i], sta[i+1]);
       ans += getdis(sta[top], sta[1]);
       ans += 2*PI*l;
       printf("%d\n",(int)(ans + 0.500001));
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值