【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. ...
随机推荐
- CPU和GPU性能对比
计算20000次10000点的fft,分别使用CPU和GPU,得 the running time of cpu is : 2.3696s the running time of gpu is : 0 ...
- Nginx反向代理和负载均衡——个人配置
#user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...
- gnuplot 的安装
需要同时安装gnuplot和gnuplot-x11才能画出图 sudo apt-get install gnuplot gnuplot-x11 gnuplot not showing the grap ...
- angular的uiRouter服务学习(5) --- $state.includes()方法
$state.includes方法用于判断当前激活状态是否是指定的状态或者是指定状态的子状态. $state.includes(stateOrName,params,options) $state.i ...
- Linux下误删除后的恢复操作(ext3/ext4)
Linux是作为一个多用户.多任务的操作系统,文件一旦被删除是难以恢复的.尽管删除命令只是在文件节点中作删除标记,并不真正清除文件内容,但是其他用户和一些有写盘动作的进程会很快覆盖这些数据.在日常工程 ...
- jquery.validate.min.js 用法方法示例
页面html 代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- PHP命令行模式
<?php error_reporting(E_ALL); header('Content-Type:text/plain;charset=utf-8'); interface CommandA ...
- switch2osm使用open street map离线地图中文乱码方框解决办法
----------written by shenwenkai------------- ubuntu linux环境下,按照网址(https://switch2osm.org/serving-til ...
- 由于 ASP.NET 进程标识对全局程序集缓存没有读权限,因此未能执行请求。错误: 0x80131902
由于 ASP.NET 进程标识对全局程序集缓存没有读权限,因此未能执行请求.错误: 0x80131902 分类: c#2013-06-17 10:22 89人阅读 评论(0) 收藏 举报 ASP.NE ...
- FineUI(专业版)高清大图赏析!(第二波)
FineUI(专业版)是由三生石上全新打造的基于 jQuery 的专业 ASP.NET 控件库,计划在七月下旬正式发布. 选择FineUI(专业版)的四大理由:1. 简单:专业版和开源版兼容(v4.x ...