zoukankan      html  css  js  c++  java
  • poj1113

    题意:给定一些点,求围住这些点的墙的长度,强要求与这些点至少距离为R

    思路:凸包,然后还要加上一个圆周长(画一下就知道了)

    code:

     1 /*
     2   State:Accepted
     3   Time:2013-03-24 20:58:46
     4 */
     5 #include <iostream>
     6 #include <cstdlib>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <fstream>
    10 #include <cmath>
    11 #include <algorithm>
    12 using namespace std;
    13 struct oo{ int x, y; };
    14 int n ,L, xt, yt;
    15 oo a[1500], q[2000];
    16 
    17 void init(){
    18      scanf("%d%d",&n ,&L);      
    19      for (int i = 1; i <= n ; ++i)
    20          scanf("%d%d",&a[i].x , &a[i].y); 
    21      
    22 }
    23 
    24 bool cmp(const oo a, const oo b){
    25      if (a.x <b.x || a.x == b.x && a.y < b.y) return true;
    26      return false;
    27 }
    28 
    29 bool cmp1(const oo a , const oo b ){
    30      int x1 = a.x - xt;
    31      int x2 = b.x - xt;
    32      int y1 = a.y - yt;
    33      int y2 = b.y - yt;
    34      if (x1*y2 > x2*y1) return true;
    35      if (x1*y2 == x2*y1 && x1*x1 + y1*y1 < x2*x2 + y2*y2) return true;
    36      return false;
    37      
    38 }
    39 
    40 void solve(){
    41      sort(a+1, a+n+1,cmp);
    42      xt = a[1].x;
    43      yt = a[1].y;
    44      sort(a+2, a+n+1,cmp1);
    45      int h = 1, t = 2;
    46      q[h] = a[1];
    47      q[t] = a[2];
    48      int x2 , y2 , x1, y1;
    49      for (int i = 3; i <= n ;++i){
    50           while (h < t){
    51              x1 = a[i].x - q[t - 1].x;
    52              y1 = a[i].y - q[t - 1].y;
    53              x2 = q[t].x - q[t - 1].x;
    54              y2 = q[t].y - q[t - 1].y;
    55              if (x1*y2 - x2*y1 >= 0) --t;
    56              else break;
    57           }
    58           q[++t] = a[i];
    59      }   
    60      
    61      double ans = 0 ,dxy;
    62      q[++t] = q[1];
    63      for (int i = 2; i <= t; ++i){
    64          x1 = q[i].x - q[i-1].x;
    65          y1 = q[i].y - q[i-1].y;
    66          dxy = x1*x1 + y1*y1;
    67          ans += pow(dxy, 0.5);
    68      }
    69      ans += double(3.14159265358979)*L*2;
    70      printf("%.0f\n",ans);
    71 }
    72 
    73 int main(){
    74      freopen("poj1113.in","r",stdin);
    75      freopen("poj1113.out","w",stdout);
    76      init();
    77      solve();
    78      fclose(stdin); fclose(stdout);
    79 }
  • 相关阅读:
    这两天又是一次巨大的飞跃
    防范式编程:
    泛型那点儿事儿 泛型概述 简单样例代码
    FindPrivateKey X509
    Remoting Generic Async Queue (Release 3) 不受 Remoting 对象生存期过期约束
    AntiXSS Library v3.0
    X509 static RSACryptoServiceProvider 高并发加解密
    EncodingHelper Identify Encoding by BOM
    NetStatTool
    EditPlus 于 20090602 升级到 v3.11(340)
  • 原文地址:https://www.cnblogs.com/yzcstc/p/3015706.html
Copyright © 2011-2022 走看看