Triathlon

【题目链接】Triathlon

【题目类型】半平面交

&题解:

做了2道了,感觉好像套路,都是二分答案,判断半平面交是否为空.

还有刘汝佳的代码总是写const +& 但是我今天试了6次,3次const +& 和3次直接参数传值,发现时间只差了5ms左右,所以我觉得以后不用总是写const +&,因为写的代码长了,但又没有加快多少.

&代码:

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std; struct Point {
double x, y;
Point(double x = 0, double y = 0): x(x) , y(y) {}
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (const Vector& A, const Vector& B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x * p, A.y * p); }
double Dot(const Vector& A, const Vector& B) { return A.x * B.x + A.y * B.y; }
double Cross(const Vector& A, const Vector& B) { return A.x * B.y - A.y * B.x; }
double Length(const Vector& A) { return sqrt(Dot(A, A)); }
Vector Normal(const Vector& A) { double l = Length(A) ; return Vector(-A.y / l , A.x / l); } double PolygonArea(vector<Point> p) {
int n = p.size();
double ans = 0;
for(int i = 1; i < n - 1; i++) {
ans += Cross(p[i] - p[0], p[i + 1] - p[0]);
}
return ans / 2;
} struct Line {
Point p, v;
double ang;
Line() {}
Line(Point p, Vector v): p(p), v(v) { ang = atan2(v.y, v.x);}
bool operator < (const Line& l) const {
return ang < l.ang;
}
}; bool OnLeft(const Line& l, const Point& p) {
return Cross(l.v, p - l.p) > 0;
} Point GetLineIntersection(const Line& a, const Line& b) {
Vector u = a.p - b.p;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.p + a.v * t;
} const double eps = 1e-6; vector<Point> HalfplaneIntersection(vector<Line> L) {
int n = L.size();
sort(L.begin(), L.end());
int first, last;
vector<Point> p(n), ans;
vector<Line> que(n);
que[first = last = 0] = L[0];
for(int i = 1; i < n; i++) {
while(first < last && !OnLeft(L[i], p[last - 1])) last--;
while(first < last && !OnLeft(L[i], p[first])) first++;
que[++last] = L[i];
if(fabs(Cross(que[last].v, que[last - 1].v)) < eps) {
last--;
//This is que[last] not que[i]
if(OnLeft(que[last], L[i].p)) que[last] = L[i];
}
if(first < last) {
p[last - 1] = GetLineIntersection(que[last - 1], que[last]);
}
}
while(first < last && !OnLeft(que[first], p[last - 1])) last--;
if(last - first <= 1) return ans;
p[last] = GetLineIntersection(que[last], que[first]);
for(int i = first; i <= last; i++)
ans.push_back(p[i]);
return ans;
} const int maxn = 110;
int V[maxn], U[maxn], W[maxn]; int main() {
//("E:1.in", "r", stdin);
int n;
while(scanf("%d", &n) == 1 && n) {
for(int i = 0; i < n; i++) {
scanf("%d%d%d", &V[i], &U[i], &W[i]);
}
for(int i = 0; i < n; i++) {
int ok = 1;
double k = 10000;
vector<Line> L;
for(int j = 0; j < n; j++) if(i != j) {
if(V[i] <= V[j] && U[i] <= U[j] && W[i] <= W[j]) { ok = 0; break; }
if(V[i] >= V[j] && U[i] >= U[j] && W[i] >= W[j]) { continue; }
double a = (k / V[j] - k / W[j]) - (k / V[i] - k / W[i]);
double b = (k / U[j] - k / W[j]) - (k / U[i] - k / W[i]);
double c = k / W[j] - k / W[i];
Point p;
Vector v(b, -a);
if(fabs(a) > fabs(b)) p = Point(-c / a , 0);
else p = Point(0 , -c / b);
L.push_back(Line(p, v));
}
if(ok) {
// x>0, y>0, x+y<1 ==> -x-y+1>0
L.push_back(Line(Point(0, 0), Vector(0, -1)));
L.push_back(Line(Point(0, 0), Vector(1, 0)));
L.push_back(Line(Point(0, 1), Vector(-1, 1)));
vector<Point> poly = HalfplaneIntersection(L);
if(poly.empty()) ok = 0;
}
puts(ok ? "Yes" : "No");
}
}
return 0;
}

LA 2218 Triathlon(半平面交)的更多相关文章

  1. POJ 1755 Triathlon [半平面交 线性规划]

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6912   Accepted: 1790 Descrip ...

  2. LA2218 Triathlon /// 半平面交 oj22648

    题目大意: 铁人三项分连续三段:游泳 自行车 赛跑 已知各选手在每个单项中的速度v[i],u[i],w[i] 设计每个单项的长度 可以让某个特定的选手获胜 判断哪些选手有可能获得冠军 输出n行 有可能 ...

  3. LA 2218 (半平面交) Triathlon

    题意: 有n个选手,铁人三项有连续的三段,对于每段场地选手i分别以vi, ui 和 wi匀速通过. 对于每个选手,问能否通过调整每种赛道的长度使得他成为冠军(不能并列). 分析: 粗一看,这不像一道计 ...

  4. POJ 1755 Triathlon (半平面交)

    Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4733   Accepted: 1166 Descrip ...

  5. POJ 1755 Triathlon(线性规划の半平面交)

    Description Triathlon is an athletic contest consisting of three consecutive sections that should be ...

  6. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  7. LA 3890 (半平面交) Most Distant Point from the Sea

    题意: 给出一个凸n边形,求多边形内部一点使得该点到边的最小距离最大. 分析: 最小值最大可以用二分. 多边形每条边的左边是一个半平面,将这n个半平面向左移动距离x,则将这个凸多边形缩小了.如果这n个 ...

  8. LA 4992 Jungle Outpost(半平面交)

    Jungle Outpost [题目链接]Jungle Outpost [题目类型]半平面交 &题解: 蓝书282 我自己写的代码居然AC了!!! 刘汝佳的说要right要-3什么的,还要特判 ...

  9. LA 3890 Most Distant Point from the Sea(半平面交)

    Most Distant Point from the Sea [题目链接]Most Distant Point from the Sea [题目类型]半平面交 &题解: 蓝书279 二分答案 ...

随机推荐

  1. [No0000F5]C# 类(Class)

    当你定义一个类时,你定义了一个数据类型的蓝图.这实际上并没有定义任何的数据,但它定义了类的名称意味着什么,也就是说,类的对象由什么组成及在这个对象上可执行什么操作.对象是类的实例.构成类的方法和变量成 ...

  2. 内存proc详解

    Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它常见的文件系统不同的是,/proc是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过 ...

  3. [daily] 在CentOS7中使用 sanitizer-address 发现内存问题 / CentOS7使用SCLo软件源安装devtoolset软件

    接前文: [daily] 内存越界的分析与定位 如前文提及, 使用sanitizer-address 可以有效的检查程序的内存问题. 当时在CentOS7中,虽然也可以使用,但是却遇到如下两个问题: ...

  4. (未完成)在block内如何修改block外部变量

    变量必须用__block修饰,否则编译不通过 block内部会把变量拷贝到堆区 变量从栈区copy->堆区 通过对对象取地址,打印出对象在内存中的地址 &a block不允许修改外部变量 ...

  5. winform窗体启动过程

    窗体启动执行顺序:FormShowFormPaintFormActivateFormResize 关闭窗体过程FormCloseFormDestroy 最小化再最大化:FormPaintFormRes ...

  6. 对称加密----AES和DES加密、解密

    目前主流的加密方式有:(对称加密)AES.DES        (非对称加密)RSA.DSA 调用AES/DES加密算法包最精要的就是下面两句话: Cipher cipher = Cipher.get ...

  7. Python开发【笔记】:PEP 8 编码规范

    PEP 8 编码规范     https://bk.tencent.com/document/bkrule/040101.pdf                                     ...

  8. Python接口自动化【requests处理Token请求】

    首先说一下使用python模拟登录或注册时,对于带token的页面怎么登录注册模拟的思路: 1.对于带token的页面,需要先从最开始的页面获取合法token 2.然后使用获取到的合法token进行后 ...

  9. vue中watch的详细用法

    在vue中,使用watch来响应数据的变化.watch的用法大致有三种.下面代码是watch的一种简单的用法: <input type="text" v-model=&quo ...

  10. ext3文件系统挂载优化--HBase

    1.设置noatime属性禁止记录文件访问时间戳以减少内核的管理开销 2.优化磁盘每个块为关键系统进程保留的固定空间:这个功能对关键磁盘比较有用, 比如操作系统依赖的磁盘,但这个功能对于数据存储来说几 ...