bzoj1670
第一道凸包
采用Andrew算法,不论实现还是理解都非常简单
var q,x,y:array[..] of longint;
i,j,k,m,n:longint;
ans:double; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r: longint);
var i,j,p,q: longint;
begin
i:=l;
j:=r;
p:=x[(l+r) shr ];
q:=y[(l+r) shr ];
repeat
while (x[i]<p) or (x[i]=p) and (y[i]<q) do inc(i);
while (p<x[j]) or (p=x[j]) and (q<y[j]) do dec(j);
if not(i>j) then
begin
swap(x[i],x[j]);
swap(y[i],y[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; function check(i,j,k:longint):longint;
begin
exit((y[i]-y[k])*(x[j]-x[k])-(y[j]-y[k])*(x[i]-x[k]));
end; function calc(i,j:longint):double;
begin
exit(sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j])));
end; begin
readln(n);
for i:= to n do
readln(x[i],y[i]);
sort(,n);
m:=;
q[]:=;
for i:= to n do
begin
while (m>) and (check(i,q[m],q[m-])<) do dec(m);
inc(m);
q[m]:=i;
end;
k:=m-;
for i:=n- downto do
begin
while (m>k) and (check(i,q[m],q[m-])<) do dec(m);
inc(m);
q[m]:=i;
end;
for i:= to m do
ans:=ans+calc(q[i],q[i-]);
writeln(ans::);
end.
bzoj1670的更多相关文章
- [bzoj1670][Usaco2006 Oct]Building the Moat
Description 为了防止口渴的食蚁兽进入他的农场,$Farmer John$决定在他的农场周围挖一条护城河.农场里一共有$N$股泉水,并且,护城河总是笔直地连接在河道上的相邻的两股泉水.护城河 ...
- 【BZOJ-1670】Building the Moat护城河的挖掘 Graham扫描法 + 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 464 Solv ...
- bzoj1670 Usaco2006 Building the Moat护城河的挖掘 [凸包模板题]
Description 为了防止口渴的食蚁兽进入他的农场,Farmer John决定在他的农场周围挖一条护城河.农场里一共有N(8<=N<=5,000)股泉水,并且,护城河总是笔直地连接在 ...
- BZOJ1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
裸的凸包...(和旋转卡壳有什么关系吗...蒟蒻求教T T) 话说忘了怎么写了...(我以前都是先做上凸壳再做下凸壳的说) 于是看了下hzwer的写法,用了向量的点积,方便多了,于是果断学习(Orz) ...
- 【计算几何】【凸包】bzoj1670 [Usaco2006 Oct]Building the Moat护城河的挖掘
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; #define ...
- bzoj1670【Usaco2006 Oct】Building the Moat 护城河的挖掘
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 387 Sol ...
- BZOJ第7页养成计划
嗯,用这篇博客当一个目录,方便自己和学弟(妹?)们查阅.不定期更新. BZOJ1600 BZOJ1601 BZOJ1602 BZOJ1603 BZOJ1604 BZOJ1605 ...
- [转载]hzwer的bzoj题单
counter: 664BZOJ1601 BZOJ1003 BZOJ1002 BZOJ1192 BZOJ1303 BZOJ1270 BZOJ3039 BZOJ1191 BZOJ1059 BZOJ120 ...
- BZOJ刷题列表【转载于hzwer】
沿着黄学长的步伐~~ 红色为已刷,黑色为未刷,看我多久能搞完吧... Update on 7.26 :之前咕了好久...(足见博主的flag是多么emmm......)这几天开始会抽时间刷的,每天几道 ...
随机推荐
- spring mvc 全局异常处理
package com.tool; public class MyException extends Exception{ public String Msg; public String ErrCo ...
- Gulp实战(二)
一.配置环境 1.基于NodeJs安装Git,npm,gulp 2.安装各类插件 3.参考文档 http://www.tuicool.com/articles/UbaqyyJ http://www.t ...
- JSP编程中常用的JavaScript技术(转载)
1.<tronMouseOver=this.style.backgroundColor=’#FFFFFF’ onMouseOut=this.style.backgroundColor=”> ...
- osi七层模型和两主机传输过程:
osi七层模型和两主机传输过程: http://www.zhihu.com/question/24002080/answer/31817536 注:笔记部分可能参考其他作者内容的一个记录,仅为加深自 ...
- 栈(顺序存储)C++模板实现
#include <iostream> using namespace std; template <typename T> class stack{ private: int ...
- Ubuntu14.04 LTS安装不成功
北京时间2014年04月18日早8:00时,Ubuntu14.04 LTS在ubuntu官网放出,果断下之体验. 镜像为ubuntu-14.04-desktop-amd64.iso.大小为964M.M ...
- js简单实现删除记录时的提示效果
删除记录时的提示效果,挺人性化的,实现的方法有很多,在本文为大家介绍下使用js是如何实现的 样式 复制代码代码如下: <style type="text/css"> ...
- firemonkey 得到屏幕信息
type TO_MONITOR = class hm: HMONITOR; end; function EnumMonitorsProc(hm: HMONITOR; dc: HDC; r: PRect ...
- 同样的一句SQL语句在pl/sql 代码块中count 没有数据,但是直接用SQl 执行却可以count 得到结果
pl/sql 代码块: SELECT count(distinct t2.so_nbr) INTO v_count2 FROM KFGL_YW_STEP_qd t2 WHERE t2.partitio ...
- hdu 3157 Crazy Circuits 有源汇和下界的最小费用流
题目链接 题意:有n个节点,m个用电器.之后输入m行每行三个整数a,b,c; 节点a为正极(或者a 为 '+'即总的正极),b为该用电器的负极(b = '-'表示总的负极),c为该用电器要正常工作最小 ...