zoukankan      html  css  js  c++  java
  • POJ 1113 Wall

    这个的题意是绕一圈使得圈上所有点到原来的点的距离都大于等于l。求最短周长。

    平移一下,几何乱搞?发现这个弧线刚好是个圆。

    convexhull。。这个我抄的版也不知道是什么算法但是好像靠谱。研究凸包的一个算法。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    struct point
    {
    int x,y;
    point(int x=0,int y=0):x(x),y(y){}
    };
    typedef point vector;
    point ch[1010],p[1010];
    const double pi=atan(1.0)*4;
    int n;
    int cross(vector a,vector b)
    {
    return a.x*b.y-a.y*b.x;
    }
    vector operator + (vector a,vector b)
    {
    return vector(a.x+b.x,a.y+b.y);
    }
    vector operator - (vector a,vector b)
    {
    return vector(a.x-b.x,a.y-b.y);
    }
    vector operator * (vector a,double p)
    {
    return vector(a.x*p,a.y*p);
    }
    vector operator / (vector a,double p)
    {
    return vector(a.x/p,a.y/p);
    }
    bool operator < (point a,point b)
    {
    return a.x<b.x||(a.x==b.x && a.y<b.y);
    }
    double dis(point a,point b)
    {
    return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    int convexhull()
    {
    sort(p,p+n);
    int m=0,k;
    for (int i=0;i<n;i++)
    {
    while (m>1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
    m--;
    ch[m++]=p[i];
    }
    k=m;
    for (int i=n-2;i>=0;i--)
    {
    while (m>k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
    m--;
    ch[m++]=p[i];
    }
    if (n>1) m--;
    return m;
    }
    int main()
    {
    int l;
    while (scanf("%d%d",&n,&l)==2)
    {
    for (int i=0;i<n;i++)
    scanf("%d%d",&p[i].x,&p[i].y);
    int m=convexhull();
    double ans=0;
    for (int i=1;i<m;i++)
    ans=ans+dis(ch[i-1],ch[i]);
    ans=ans+dis(ch[0],ch[m-1]);
    ans=ans+2.0*pi*l;
    printf("%d ",int(ans+0.5));
    }
    return 0;
    }

  • 相关阅读:
    【NOIp模拟赛】种花
    【NOIP模拟赛】质数序列
    【NOIp模拟赛】兔子
    【NOIp模拟赛】圆桌游戏
    【NOIp模拟赛】花
    【洛谷P2345】奶牛集会
    【洛谷P1774】最接近神的人_NOI导刊2010提高(02)
    【洛谷P1495】 曹冲养猪
    【洛谷P1287】 盒子与球
    NOIP2009 Hankson 的趣味题
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/5055674.html
Copyright © 2011-2022 走看看