http://poj.org/problem?id=1113

夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题

我WA两次错在四舍五入上了(=゚ω゚)ノ

  1. #include<cmath>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6. double Pi = acos(-1);
  7. const int N = 1003;
  8.  
  9. struct Point {
  10. double x, y;
  11. Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
  12. bool operator < (const Point &A) const {
  13. return x == A.x ? y < A.y : x < A.x;
  14. }
  15. } a[N], tu[N];
  16. int top = 1;
  17.  
  18. Point operator + (Point a, Point b) {return Point(a.x + b.x, a.y + b.y);}
  19. Point operator - (Point a, Point b) {return Point(a.x - b.x, a.y - b.y);}
  20. Point operator * (Point a, double x) {return Point(a.x * x, a.y * x);}
  21. Point operator / (Point a, double x) {return Point(a.x / x, a.y / x);}
  22.  
  23. double Dot(Point a, Point b) {return a.x * b.x + a.y * b.y;}
  24. double Cross(Point a, Point b) {return a.x * b.y - a.y * b.x;}
  25. double sqr(double x) {return x * x;}
  26. double dis(Point a, Point b) {return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));}
  27.  
  28. int dcmp(double x) {return fabs(x) < 1e-8 ? 0 : (x < 0 ? -1 : 1);}
  29.  
  30. void mktb(int n) {
  31. tu[1] = a[1];
  32. for(int i = 2; i <= n; ++i) {
  33. while (top > 1 && dcmp(Cross(a[i] - tu[top], tu[top] - tu[top - 1])) <= 0) --top;
  34. tu[++top] = a[i];
  35. }
  36. int k = top;
  37. for(int i = n - 1; i >= 1; --i) {
  38. while (top > k && dcmp(Cross(a[i] - tu[top], tu[top] - tu[top - 1])) <= 0) --top;
  39. tu[++top] = a[i];
  40. }
  41. }
  42.  
  43. int main() {
  44. int n, l;
  45. scanf("%d%d", &n, &l);
  46. for(int i = 1; i <= n; ++i) scanf("%lf%lf", &a[i].x, &a[i].y);
  47.  
  48. sort(a + 1, a + n + 1);
  49.  
  50. mktb(n);
  51.  
  52. double ret = 2.0 * l * Pi;
  53. for(int i = 1; i < top; ++i)
  54. ret += dis(tu[i], tu[i + 1]);
  55.  
  56. printf("%d\n", (int) (ret + 0.5));
  57. return 0;
  58. }

复习模板~

【POJ 1113】Wall的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. POJ1849Two[DP|树的直径](扩展HDU4003待办)

    Two Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1390   Accepted: 701 Description Th ...

  2. 用Access作为后台数据库支撑,书写一个用C#写入记录的案例

    具体的步骤: 1.创建并打开一个OleDbConnection对象 2.创建插入的SQL语句 3.创建一个OleDbCommand对象 4.使用OleDbCommand对象来插入数据 5.关闭OleD ...

  3. stl学习(三)crope的用法

    转载自http://blog.csdn.net/iamzky/article/details/38348653 曾经我不会写平衡树……于是在STL中乱翻……学到了pb_ds库中的SXBK的斐波那契堆. ...

  4. 阿里云日志api创建logStore

    , shardCount =  });                 string date = FormatRfc822Date(time);                 string con ...

  5. 一种Docker image镜像的取代方案

    在http://openvz.org/Download/templates/precreated中有很多压缩的镜像文件,可以将这些文件下载后采用import方式使用镜像,也可以采用我原来的博文:doc ...

  6. C语言 自动修改文件名小程序

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...

  7. KindEditor得不到textarea值的解决方法

    转自:http://blog.phpha.com/archives/510.html 以前有朋友遇到过这个问题,就是KindEditor在火狐下或者其他浏览器下都无法得到textarea文本框的值,点 ...

  8. POJO, DTO, VO, JavaBean的区别

    POJO(plain ordinary java object 简单java对象) POJO是一个简单的普通的Java对象,它不包含业务逻辑或持久逻辑等,但不是JavaBean.EntityBean等 ...

  9. leetcode - 位运算题目汇总(下)

    接上文leetcode - 位运算题目汇总(上),继续来切leetcode中Bit Manipulation下的题目. Bitwise AND of Numbers Range 给出一个范围,[m, ...

  10. 程序猿看小说还要去找TXT?自己动手爬一个TXT才是正确的打开方式

    前言 在贴吧看了个小说追了几天被删帖了,于是自己找书名,打算下载下来看,结果要么是需要充值,要么不提供下载.作为一个猿类,怎么能忍. 好在小说网站多入牛毛,有的采用js加载文字来防采集,有的用css图 ...