【POJ 1113】Wall
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的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- POJ1849Two[DP|树的直径](扩展HDU4003待办)
Two Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1390 Accepted: 701 Description Th ...
- 用Access作为后台数据库支撑,书写一个用C#写入记录的案例
具体的步骤: 1.创建并打开一个OleDbConnection对象 2.创建插入的SQL语句 3.创建一个OleDbCommand对象 4.使用OleDbCommand对象来插入数据 5.关闭OleD ...
- stl学习(三)crope的用法
转载自http://blog.csdn.net/iamzky/article/details/38348653 曾经我不会写平衡树……于是在STL中乱翻……学到了pb_ds库中的SXBK的斐波那契堆. ...
- 阿里云日志api创建logStore
, shardCount = }); string date = FormatRfc822Date(time); string con ...
- 一种Docker image镜像的取代方案
在http://openvz.org/Download/templates/precreated中有很多压缩的镜像文件,可以将这些文件下载后采用import方式使用镜像,也可以采用我原来的博文:doc ...
- C语言 自动修改文件名小程序
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <stri ...
- KindEditor得不到textarea值的解决方法
转自:http://blog.phpha.com/archives/510.html 以前有朋友遇到过这个问题,就是KindEditor在火狐下或者其他浏览器下都无法得到textarea文本框的值,点 ...
- POJO, DTO, VO, JavaBean的区别
POJO(plain ordinary java object 简单java对象) POJO是一个简单的普通的Java对象,它不包含业务逻辑或持久逻辑等,但不是JavaBean.EntityBean等 ...
- leetcode - 位运算题目汇总(下)
接上文leetcode - 位运算题目汇总(上),继续来切leetcode中Bit Manipulation下的题目. Bitwise AND of Numbers Range 给出一个范围,[m, ...
- 程序猿看小说还要去找TXT?自己动手爬一个TXT才是正确的打开方式
前言 在贴吧看了个小说追了几天被删帖了,于是自己找书名,打算下载下来看,结果要么是需要充值,要么不提供下载.作为一个猿类,怎么能忍. 好在小说网站多入牛毛,有的采用js加载文字来防采集,有的用css图 ...