UVA Wall
来源:互联网 发布:淘宝知识产权如何申请 编辑:程序博客网 时间:2024/05/26 22:59
这个题也很简单。 就是求凸包。 然后 求外围凸包的和就行。 问题就出在 没一个点的地方的处理。
因为是求最小的距离。那么在点的地方。 外围就是要求最小就是圆弧。 对于 所有的点的圆弧 加起来 正好是一个完整的圆(因为要围一圈)。
所以 最小距离 就是 凸包的距离 + 圆的周长。
#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>#include <cmath>#include <cstdlib>#include <string>#include <map>#include <vector>#include <set>#include <queue>#include <stack>#include <cctype>using namespace std;#define ll long longtypedef unsigned long long ull;#define maxn 1001#define INF 1<<30struct Point{ double x,y; Point(double x = 0, double y = 0):x(x),y(y) {}};typedef Point Vector ;Vector operator + (Vector A, Vector B){ return Vector(A.x + B.x, A.y + B.y);}Vector operator - (Vector A, Point B){return Vector(A.x - B.x, A.y - B.y);}Vector operator * (Vector A, double p){return Vector(A.x * p, A.y * p);}Vector operator / (Vector A, double p){return Vector(A.x / p, A.y / p);}bool operator < (const Point & a, const Point & b){ return a.x < b.x || (a.x == b.x && a.y < b.y);}const double eps = 1e-10;int dcmp(double x){ if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}bool operator == (const Point & a, const Point & b){ return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;}double Dot(Vector A, Vector B){ return A.x * B.x + A.y * B.y;} // 点积double Length(Vector A) { return sqrt(Dot(A, A));} //向量长度double Angle(Vector A, Vector B){ return acos(Dot(A, B)/Length(A)/Length(B));} //夹角double Cross(Vector A, Vector B){return A.x*B.y - A.y * B.x;} //叉积(面积两倍)double Area2(Point A, Point B, Point C){return Cross(B-A,C-A);} // 面积两倍Vector Rotate(Vector A, double rad){return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));}// 旋转后的直线</span>Vector Normal(Vector A){ double L = Length(A); return Vector(-A.y/L, A.x/L);}Point GetLineIntersection(Point P, Point v, Point Q, Point w){ //求直线 pv 与qw的交点 Vector u = P-Q; double t = Cross(w, u) / Cross(v, w); return P+v*t;}double DistanceToline(Point P, Point A, Point B){ //点到直线的距离 Vector v1 = B - A,v2 = P - A; return fabs(Cross(v1,v2))/Length(v1);}double DistanceTpsegment(Point P, Point A, Point B){ //点到线段的距离 if(A == B) return Length(P-A); Vector v1 = B - A, v2 = P - A, v3 = P - B; if(dcmp(Dot(v1, v2)) < 0) return Length(v2); else if(dcmp(Dot(v1,v3)) > 0) return Length(v3); else return fabs(Cross(v1, v2)) / Length(v1);}Point GetLinePrijection(Point P, Point A, Point B){ // 点在直线上的投影 Vector v = B-A; return A+v*(Dot(v, P-A)/Dot(v,v));}bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2){ // 线段相交判定(不包括在端点处的情况) double c1 = Cross(a2 - a1,b1-a1) ,c2 = Cross(a2 - a1,b2-a1), c3 = Cross(b2 - b1, a1-b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;}bool OnSegment(Point p, Point a1, Point a2){ //线段在端点处是否可能相交 return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;}double ConvexPolygonArea(Point * p,int n){ // 多边形的有向面积 double area = 0; for(int i = 1; i < n-1; i++) area += Cross(p[i] - p[0],p[i+1] - p[0]); return area/2;}int ConvexHull(Point *p, int n, Point * ch){ sort(p, p+n); int m = 0; for(int i = 0; i < n; i++){ while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--; ch[m++] = p[i]; } int k = m; for(int i = n-2; i >= 0; i--){ while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--; ch[m++] = p[i]; } if(n > 1) m --; return m;}int main (){ int kase; int counts = 0; scanf("%d",&kase); while(kase--){ if(counts) printf("\n"); counts++; int n; double r; Point p[maxn]; Point af[maxn]; scanf("%d%lf",&n,&r); for(int i = 0; i < n; i++) scanf("%lf%lf",&p[i].x,&p[i].y); int m = ConvexHull(p, n, af); double sum = 0; for(int i = 0; i < m; i++) sum += Length(af[i] - af[(i+1)%m]); double pi = acos(-1); sum += pi*r*2; printf("%.0lf\n",sum); } return 0;}
0 0
- UVA Wall
- UVa 1303 - Wall
- The Wall Pushers (UVA
- The Wall Pushers UVA
- UVA 900 Brick Wall Patterns
- UVa, 900 Brick Wall Patterns
- UVa 900 - Brick Wall Patterns
- Fixing the Great Wall UVA
- Fixing the Great Wall UVA
- (beginer) 凸包 UVA 1303 - Wall
- Uva-1045-The Great Wall Game
- Uva-1336-Fixing the Great Wall
- UVA 11040 - Add bricks in the wall
- UVa 11040 - Add bricks in the wall
- UVa 11040 - Add bricks in the wall
- UVa 1336 Fixing the Great Wall
- uva 11040 - Add bricks in the wall
- UVA 11040 Add bricks in the wall
- 2.Struts2第一个应用
- 3.Struts2 struts.xml配置和Action有关的属性
- linux进程中常用的全局数据之资源限制
- 看见了经济改革分
- poj 1050 To the Max
- UVA Wall
- Leecode-Pow(x,n)
- Pexpect简单的测试——一个 expect的python实现
- 6.Struts2 动态方法调用和参数获取
- 鲁信机床祝所有人们中秋幸福快乐
- 7.Struts2 自定义类型转换器
- 救治剩下对你的期待
- 数据结构:线性表的顺序表
- adc 采样 通道