poj 1113 凸包入门

点我看题

在这里插入图片描述

咱们先看个图:

在这里插入图片描述

看完图以后有没有觉得很显然:

答案就是求个凸包周长加一个圆的周长

#include<bits/stdc++.h>
#define maxn 1003
#define db double 
#define ll long long
#define met(a, b) memset(a, b, sizeof(a))
#define pi  acos(-1.0)
#define _rep(i, a, b) for(int i = (a); i <= (b); i++)
#define _rev(i, a, b) for(int i = (a); i >= (b); i--)
#define _for(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
struct Point
{
 db x, y;
 Point(db a, db b) : x(a), y(b) {};
 Point() {}
 bool operator < (const Point& a)const {
  return  x == a.x ? y < a.y : x < a.x;
 }
 Point operator - (const Point& a) { return Point(x - a.x, y - a.y); }
 Point operator + (const Point& a) { return Point(x + a.x, y + a.y); }
 db get_dis(const Point& a) { return sqrt((x - a.x) * (x - a.x) + (y - a.y) * (y - a.y)); }
}pnt[maxn], hull[maxn];
inline db Cross(Point a, Point b) {
 return a.x * b.y - a.y * b.x;
}
db out, r;
int n;
int ConverxHull(Point p[], int n, Point ch[]) {
 sort(pnt + 1, pnt + 1 + n);
 int m = 0;
 _rep(i, 1, n) {
  while (m > 1 && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m--;
  ch[m++] = p[i];
 }
 int k = m;
 _rev(i, n - 1, 1) {
  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() {
 ios::sync_with_stdio(0);
 int t;
 cin >> t;
 while (t--) {
  cin >> n >> r;
  db dis = 0;
  _rep(i, 1, n) {
   cin >> pnt[i].x >> pnt[i].y;
  }
  int m = ConverxHull(pnt, n, hull);
  _rep(i, 2, m) {
   dis += hull[i].get_dis(hull[i - 1]);
  }
  dis += hull[1].get_dis(hull[m]);
  met(hull, 0), met(pnt, 0);
  dis += 2 * pi * r;
  dis = (int)(dis + 0.5);
  cout << (int)dis << endl;
  if (t != 0)cout << endl;
 }
 system("pause");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值