凸包
来源:互联网 发布:mac系统能玩lol吗 编辑:程序博客网 时间:2024/06/05 08:04
Description
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.
There are no more than 100 trees.
Input
Zero at line for number of trees terminates the input for your program.
Output
Sample Input
Sample Output
A题(Graphm求凸包)
实际上就是求一个凸包,不过要注意,n=2的时候,不要将总长度乘以2。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using
struct
}
int
point
bool
}
bool
}
double
}
int
{
}
Graham's Scan法 求解凸包问题。
- #include
- #include
- #include
- #include
- using
namespace std; -
- #define
N 1005 -
- struct
Point - {
-
int x,y; - }P[N],S[N];
-
- int
n,top; -
- double
Dis( constPoint& constp1, Point& p2) - {
-
return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y)*1.0 ); - }
-
- double
Cross( constPoint& constp1, Point& constp2, Point& constp3, Point& p4) - {
-
return (p2.x-p1.x)*(p4.y-p3.y) - (p2.y-p1.y)*(p4.x-p3.x); - }
-
- bool
cmp( constPoint& constp1, Point& p2) - {
-
double C = Cross(P[0],p1,P[0],p2); -
return C ? C>0 : Dis(P[0],p1) - }
-
- void
Pole_Point() - {
-
int id; -
Point pp = P[id=0]; -
for(int i=1;i -
if(P[i].y < pp.y || P[i].y == pp.y && P[i].x < pp.x) -
pp = P[i] , id = i; -
P[id] = P[0] , P[0] = pp; - }
-
- void
Convex_Hull() - {
-
Pole_Point(); -
sort(P+1,P+n,cmp); -
S[0]=P[0],S[top=1]=P[1]; -
for(int i=2;i -
{ -
while(top && Cross(S[top-1],S[top],S[top],P[i]) <= 0) -
--top; -
S[++top] = P[i]; -
} - }
-
- int
main() - {
-
while(~scanf("%d",&n)) -
{ -
for(int i=0;i -
scanf("%d%d",&P[i].x,&P[i].y); -
Convex_Hull(); -
for(int i=0;i<=top;i++) -
printf("%d %d\n" ,S[i].x,S[i].y); -
} -
return 0; - }
//凸包structpoint{ double x, y;};
{ return(sp.x- op.x) *(ep.y- op.y) >=(ep.x- op.x) *(sp.y- op.y);}
{ returnl.y<</FONT> r.y ||(l.y== r.y &&l.x<</FONT> r.x);}
int graham(point pnt[], intn,point res[])
sort(pnt,pnt +n);
return 0;
res[0]= pnt[0];
if(n== 1)
res[1]= pnt[1];
if(n== 2) return2;
res[2]= pnt[2];
for(i= 2; i<</FONT> n; i++)
for(i= n- 3; i>= 0; i--)
}
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包。
- 凸包
- { 凸包 }
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 凸包
- 关于jQuery append生成的新元素添加事件失败
- JAVA设计模式(18):行为型-状态模式(State)
- C++小问题以及解析
- 二进制码转BCD码
- Floyd算法求解每一对顶点之间的最短路径2
- 凸包
- 如何优雅的写一个分页代码(三)
- 试设计一个算法,删除一个顺序表从第i个元素开始的k个元素
- C#中运用正则表达式获取字符串
- C语言位运算
- 第三天
- 使用VB.NET开发多线程
- 【FZU】Problem 2056 最大正方形
- PSLG,直线切割凸多边形,和判断圆与多边形相交