CS Academy Round #33 Subinterval Division
来源:互联网 发布:淘宝一折特卖网 编辑:程序博客网 时间:2024/05/16 07:13
题意: 二维空间上有集合S,S中有n个点,将x轴上(0,0)到(X,0)分成多个部分,对于每一个部分中的所有点,离S中的最近的点是相同。
注意到任意两个点的连线的中垂线都可以将一个平面分成两个半平面,每个半平面到各自的点是最近的。那么可以维护一个堆栈,对于堆栈中的n个点已经将x轴分成了n+1个部分,那么新加入的点如果不影响栈顶的点,那么也不会影响栈内的其他点,因为现在需要分割的平面是属于栈顶的点的。如果影响栈顶的点,那么pop掉,直至不影响为止。
代码:
#include<bits/stdc++.h>using namespace std;const double eps = 1e-10;const double PI = acos(-1.0);struct Point { double x, y; Point(double x=0, double y=0):x(x),y(y) {} };struct idPoint { Point p; int id; };struct Circle { Point c; double r; Circle(Point c=Point(0, 0), double r = 0):c(c),r(r) {} };typedef Point Vector;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 a.x<b.x || (a.x==b.x&&a.y<b.y); }bool operator < (const idPoint& a, const idPoint& b) { return a.p < b.p; }bool operator == (const Point& a, const Point& b) { return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0; }Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); }Vector operator - (Point 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); }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; }Vector Rotate(Vector A, double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));}//向量逆时针旋转Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) { Vector u = P-Q; double t = Cross(w, u)/Cross(v, w); return P+v*t;}//求直线交点const int N = 1e5+5;double ans[N];Point lp[N];idPoint p[N];stack<int> S;double solve(int u, int v) { Point pp = (p[u].p+p[v].p)/2; return GetLineIntersection({0,0}, {1,0}, pp, Rotate(p[v].p-pp, PI/2)).x;}int main() { int n; double X; cin >> n >> X; for(int i = 0; i < n; i++) { scanf("%lf%lf", &p[i].p.x, &p[i].p.y); p[i].id = i; } sort(p, p+n); for(int i = 0; i < n; i++) { if(S.empty()) { S.push(i); lp[i].x = 0; lp[i].y = X; continue; } while(!S.empty()) { int u = S.top(); double xx = solve(u, i); if(xx < lp[u].x) S.pop(); else { lp[u].y = xx; lp[i].x = xx; lp[i].y = X; break; } } S.push(i); } memset(ans, 0, sizeof(ans)); while(!S.empty()) { int u = S.top(); S.pop(); ans[p[u].id] = max(0.0, min(X, lp[u].y)-lp[u].x); } for(int i = 0; i < n; i++) printf("%.12f\n", ans[i]); return 0;}
阅读全文
0 0
- CS Academy Round #33 Subinterval Division
- CS Academy Round #32 Light Count
- CS Academy Round #49 C.Max Substring
- CS Academy Round #49 A, B, C
- CS Academy Round #50 D.Min Races
- CS Academy Round #43 A B C D
- CS Academy Round #44 A B C D
- CS Academy Round #49 C.Max Substring 【后缀数组】
- CS Academy Round #30 (Div. 2 only) C.Constant Sum(树状数组,区间修改,单点查询模板)
- CS Academy Distinct Neighbours 经典DP
- CS Academy cube coloring(Burnside lemma)
- CS Academy E.Triplet Min Sum(最近公共祖先 倍增法模板)
- Educational Codeforces Round 21 D. Array Division
- codeforces Round 21 808DArray Division
- Educational Codeforces Round 21 D Array Division
- python academy
- Division
- Division
- bzoj 3689: 异或之 字典树+堆
- sublime text3插件安装-第一周
- webdriver启动浏览器问题
- 学习历程
- meta标签中的http-equiv属性使用介绍
- CS Academy Round #33 Subinterval Division
- [USACO1.5]回文质数 Prime Palindromes
- 区块链2.0:智能合约
- java的抽象类和抽象方法
- recv函数返回值说明
- 刚睡醒的人——哇,太阳很好诶~~
- Java实现-格雷编码
- 数据结构:图相关概念及遍历算法
- [BZOJ 1822][JSOI2010]Frozen Nova 冷冻波:最大流