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

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

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

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double Pi = acos(-1);
const int N = 1003; struct Point {
double x, y;
Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
bool operator < (const Point &A) const {
return x == A.x ? y < A.y : x < A.x;
}
} a[N], tu[N];
int top = 1; Point operator + (Point a, Point b) {return Point(a.x + b.x, a.y + b.y);}
Point operator - (Point a, Point b) {return Point(a.x - b.x, a.y - b.y);}
Point operator * (Point a, double x) {return Point(a.x * x, a.y * x);}
Point operator / (Point a, double x) {return Point(a.x / x, a.y / x);} double Dot(Point a, Point b) {return a.x * b.x + a.y * b.y;}
double Cross(Point a, Point b) {return a.x * b.y - a.y * b.x;}
double sqr(double x) {return x * x;}
double dis(Point a, Point b) {return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));} int dcmp(double x) {return fabs(x) < 1e-8 ? 0 : (x < 0 ? -1 : 1);} void mktb(int n) {
tu[1] = a[1];
for(int i = 2; i <= n; ++i) {
while (top > 1 && dcmp(Cross(a[i] - tu[top], tu[top] - tu[top - 1])) <= 0) --top;
tu[++top] = a[i];
}
int k = top;
for(int i = n - 1; i >= 1; --i) {
while (top > k && dcmp(Cross(a[i] - tu[top], tu[top] - tu[top - 1])) <= 0) --top;
tu[++top] = a[i];
}
} int main() {
int n, l;
scanf("%d%d", &n, &l);
for(int i = 1; i <= n; ++i) scanf("%lf%lf", &a[i].x, &a[i].y); sort(a + 1, a + n + 1); mktb(n); double ret = 2.0 * l * Pi;
for(int i = 1; i < top; ++i)
ret += dis(tu[i], tu[i + 1]); printf("%d\n", (int) (ret + 0.5));
return 0;
}

复习模板~

【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. Java的cmd配置(也即Java的JDK配置及相关常用命令)——找不到或无法加载主类 的解决方法

    Java的cmd配置(也即Java的JDK配置及相关常用命令) ——找不到或无法加载主类  的解决方法 这段时间一直纠结于cmd下Java无法编译运行的问题.主要问题描述如下: javac 命令可以正 ...

  2. AC日记——找最大数序列 openjudge 1.9 10

    10:找最大数序列 总时间限制:  1000ms 内存限制:  65536kB 描述 输入n行,每行不超过100个无符号整数,无符号数不超过4位.请输出最大整数以及最大整数所在的行号(行号从1开始). ...

  3. GitHub 下载文件夹

    工具 TortoiseSVN 步骤 1.打开要下载的项目,选中要下载的文件夹,右键 选择 复制链接地址 2.把链接中的 tree/master 改成 trunk ,(trunk是master分支,可以 ...

  4. 用FLASH,安智和IOS打电话方法

     打电话?你直接urlrequest不就打出去了吗普通网页http://xxx电话tel://xxx要啥ane 

  5. 转: vim 的编辑格式设置

    http://www.cnblogs.com/freewater/archive/2011/08/26/2154602.html :set encoding=utf-8:set fileencodin ...

  6. jsonobject 遍历 org.json.JSONObject

    import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public static  ...

  7. UIDate(时间)

    1.时间与时间的比较 ["时间1" timeIntervalSinceDate:"时间2"] >= 0;

  8. charCode与keyCode的区别

    在标准浏览器下获取键盘按键我们可以使用e.which,但是非标准下没有这个属性,所以大部分情况下用keyCode,但是这是存在兼容性问题的.我们来看下他两的区别: onkeydown: e.keyCo ...

  9. Java 基础命名空间

    java.lang (提供利用 Java 编程语言进行程序设计的基础类)java.lang.annotation(提供了引用对象类,支持在某种程度上与垃圾回收器之间的交互)java.lang.inst ...

  10. QT 数据库编程三

    //mainwindow.cpp #include "mainwindow.h" #include "logindlg.h" #include "sc ...