【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. ...
随机推荐
- NOIP2003加分二叉树[树 区间DP]
题目描述 设一个n个节点的二叉树tree的中序遍历为(1,2,3,…,n),其中数字1,2,3,…,n为节点编号.每个节点都有一个分数(均为正整数),记第i个节点的分数为di,tree及它的每个子树都 ...
- ural Infernal Work
Infernal Work Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descr ...
- poj 3264
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 44594 Accepted: 20931 ...
- IE兼容forEach/map/every/some/indexOf/filter
some if (!Array.prototype.some){ Array.prototype.some = function(fun /*, thisArg */) { 'use strict'; ...
- JavaScript Date对象 日期获取函数
JavaScript Date对象使用小例子: 运行结果: 总结: 1.尽管我们认为12月是第12个月份,但是JavaScript从0开始计算月份,所以月份11表示12月: 2.nowDate.set ...
- GridView EmptyDataTemplate 动态显示
以下语句加在GridView.DataBind()之后: Table GridViewTable = ((Table)gvGridView.Controls[]); if (!isSearch) (( ...
- [资料]mysql实现地理位置搜索
mysql实现地理位置搜索 使用mysql来实现lbs(地理位置服务)功能 Mysql 地区经纬度 查询
- QT 网络编程一
QT如果要进行网络编程首先需要在.pro中添加如下代码:QT += network 在头文件中包含相关头文件 #include <QHostInfo> #include <QNetw ...
- jQuery使用.on()无法绑定hover
发现好像没有hover这个事件,jQuery的hover事件是一个封装,hover算不得一个事件.他只是将mouseover和mouseout合并了用mouseover和mouseout两个配合效果好 ...
- Oracle字符分隔函数(split)
为了让 PL/SQL 函数返回数据的多个行,必须通过返回一个 REF CURSOR 或一个数据集合来完成.REF CURSOR 的这种情况局限于可以从查询中选择的数据,而整个集合在可以返回前,必须进行 ...