• 1348


     1 #include<iostream>
     2 #include<algorithm>
     3 #include<string>
     4 #include<vector>
     5 #include<map>
     6 #include<set>
     7 #include<cstring>
     8 #include<cstdio>
     9 #include<cmath>
    10 #include<cstdlib>
    11 #include<stack>
    12 #include<iomanip>
    13 #include<cctype>
    14 #include<climits>
    15 #include<queue>
    16 using namespace std;
    17 typedef long long ll;
    18 typedef unsigned long long ull;
    19 
    20 struct P
    21 {
    22     int x,y;
    23 
    24 };
    25 
    26 const int maxn=50010;
    27 int n,k;
    28 P ps[maxn];
    29 
    30 bool cmp_x(const P& p,const P& q)
    31 {
    32     if(p.x!=q.x)
    33         return p.x<q.x;
    34     return p.y<q.y;
    35 }
    36 
    37 int det(P p0,P p1,P p2)
    38 {
    39     return (p2.x-p0.x)*(p1.y-p0.y)-(p1.x-p0.x)*(p2.y-p0.y);
    40 
    41 }
    42 
    43 vector<P> convex_hull(P* ps,int n)
    44 {
    45     sort(ps,ps+n,cmp_x);
    46     k=0;
    47     vector<P> qs(n*2);
    48     for(int i=0;i<n;i++){
    49         while(k>1 && det(qs[k-2],qs[k-1],ps[i])<=0)
    50             k--;
    51         qs[k++]=ps[i];        
    52     }
    53     for(int i=n-2,t=k;i>=0;i--){
    54         while(k>t && det(qs[k-2],qs[k-1],ps[i])<=0)
    55             k--;
    56         qs[k++]=ps[i];        
    57     }
    58     k--;
    59     qs.resize(k);
    60     return qs;
    61 }
    62 
    63 double dist(P p,P q)
    64 {
    65     double dis= (p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y);
    66     return sqrt(dis);
    67 }
    68 
    69 int main()
    70 {
    71     int t,r;
    72     double ans,l;
    73     cin>>t;
    74     for(int j=0;j<t;j++){
    75         scanf("%d%d",&n,&r);
    76         l=2.0*3.14159*r;//常数放前面,且设为浮点型
    77         for(int i=0;i<n;i++)
    78             scanf("%d %d",&ps[i].x,&ps[i].y);
    79         vector<P> qs=convex_hull(ps,n);
    80         ans=0;
    81         for(int i=0;i<k-1;i++)
    82             ans+=dist(qs[i],qs[i+1]);
    83         ans+=dist(qs[0],qs[k-1]);
    84         ans+=l;
    85         printf("%.0f
    ",ans);
    86         if(j!=t-1)
    87             printf("
    ");
    88     }
    89     return 0;
    90 
    91 }
    做题笔记,只是想积累看看四年之后写了AC了多少题。
  • 相关阅读:
    如何处理DateTime日期时间格式
    ASP.NET访问域用户(AD活动目录)信息的类
    多层代理取真实IP地址
    自动播放MP3文件
    Windows7 下用 grub4dos 安装 Ubuntu
    javascript判断iphone/android手机横竖屏模式
    C#一个到多个Cookie的字符串添加到CookieCollection集合中【isGood代码】
    css 文本对齐4种方法
    让VirtualBox虚拟机实现开机自动后台运行
    MSXML2, XmlHttpClass基础
  • 原文地址:https://www.cnblogs.com/ooozy/p/6275184.html
Copyright © 2020-2023  润新知