zoukankan      html  css  js  c++  java
  • HDU 1348 和 POJ 1113 wall

    首先,这次换了个算法来写,我用了Melkman

    问题就来了,不知道怎么的,POJ1113的话,代码上去倒是可以AC。。。

    但是在HDU的时候自己就o(╯□╰)o。。。

    到底是怎么疑惑ing。。。。

    View Code
     1     #include <iostream>
     2     #include <algorithm>
     3     #include <stdio.h>
     4     #include <math.h>
     5     #include <string.h>
     6     using namespace std;
     7     const int maxn = 10005;
     8     const double pi = 3.1415926;
     9     int rear,pre,ans[2*maxn];
    10 
    11     struct Point
    12     {
    13         float x,y;
    14     }p[maxn];
    15 
    16     bool cmp(Point a,Point b)
    17     {
    18         if(a.x!=b.x)
    19             return a.x<b.x;
    20         else
    21             return a.y<b.y;
    22     }
    23 
    24     double xmult(Point p1,Point p2,Point p0)
    25     {
    26         return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    27     }
    28 
    29     double dis(Point p,Point q)
    30     {
    31         return (p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y);
    32     }
    33 
    34     void Melkman(int n)
    35     {
    36         int i,t;
    37         rear=n;
    38         pre=n;
    39         ans[pre]=0;    ans[++rear]=1;
    40         for(i=2;i<n;i++)
    41         {
    42             if(xmult(p[ans[rear-1]],p[ans[rear]],p[i])!=0)
    43                 break;
    44             ans[rear]=i;
    45         }
    46         ans[++rear]=i;    ans[--pre]=i;
    47         if(xmult(p[ans[rear-2]],p[ans[rear-1]],p[ans[rear]])<0)
    48         {
    49             t=ans[rear-2];
    50             ans[rear-2]=ans[rear-1];
    51             ans[rear-1]=t;
    52         }
    53         for(i++;i<n;i++)
    54         {
    55             if(xmult(p[ans[rear-1]],p[ans[rear]],p[i])>0&&xmult(p[ans[pre]],p[ans[pre+1]],p[i])>0)
    56                 continue;
    57             while(xmult(p[ans[rear-1]],p[ans[rear]],p[i])<=0)
    58                 --rear;
    59             ans[++rear]=i;
    60             while(xmult(p[ans[pre]],p[ans[pre+1]],p[i])<=0)
    61                 ++pre;
    62             ans[--pre]=i;
    63         }
    64     }
    65 
    66     int main()
    67     {
    68         long n,m,i,t,j,len;
    69         cin>>t;
    70         while(t--)
    71         {
    72             memset(ans,0,sizeof(ans));
    73             cin>>n>>m;
    74             for(i=0;i<n;i++)
    75                 cin>>p[i].x>>p[i].y;
    76             sort(p,p+n,cmp);
    77             Melkman(n);
    78             double sum=0;
    79             for(i=pre;i<rear;i++)
    80             {
    81                  sum+=sqrt(dis(p[ans[i]],p[ans[i+1]]));
    82                  //cout<<p[ans[i]].x<<" "<<p[ans[i]].y<<endl;
    83             }
    84             sum+=2*pi*m;
    85             printf("%.0lf\n",sum);
    86             if(t)
    87                 cout<<endl;
    88         }
    89         return 0;
    90     }

    烦...

  • 相关阅读:
    Sql Server 2008卸载后再次安装一直报错
    listbox 报错 Cannot have multiple items selected when the SelectionMode is Single.
    Sql Server 2008修改Sa密码
    学习正则表达式
    Sql Server 查询第30条数据到第40条记录数
    Sql Server 复制表
    Sql 常见面试题
    Sql Server 简单查询 异步服务器更新语句
    jQuery stop()用法以及案例展示
    CSS3打造不断旋转的CD封面
  • 原文地址:https://www.cnblogs.com/yoru/p/2709919.html
Copyright © 2011-2022 走看看