题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2052
Time Limit: 5 Seconds Memory Limit: 32768 KB

Description

Triathlon is an athletic contest consisting of three consecutive sections that should be completed as fast as possible as a whole. The first section is swimming, the second section is riding bicycle and the third one is running.

The speed of each contestant in all three sections is known. The judge can choose the length of each section arbitrarily provided that no section has zero length. As a result sometimes she could choose their lengths in such a way that some particular contestant would win the competition.

Input

The first line of the input contains integer number N (1 <= N <= 100), denoting the number of contestants. Then N lines follow, each line contains three integers Vi, Ui and Wi (1 <= Vi, Ui, Wi <= 10000), separated by spaces, denoting the speed of ith contestant in each section.

Output

For every contestant write to the output one line, that contains word "Yes" if the judge could choose the lengths of the sections in such a way that this particular contestant would win (i.e. she is the only one who would come first), or word "No" if this is impossible.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Sample Input

1

9
10 2 6
10 7 3
5 6 7
3 2 7
6 2 6
3 5 7
8 4 6
10 4 2
1 8 7

Sample Output

Yes
Yes
Yes
No
No
No
Yes
No
Yes

Problem solving report:

Description: 有n个人参加三项比赛,你作为一个裁判可以随意调整三个赛段的距离(都大于0),问是否能调整使得指定的选手获胜。
Problem solving: 题目实际上是给出了n个式子方程,Ti=Ai*x+Bi*y+Ci*z,0<i<n。
要判断第i个人能否获胜,即判断不等式组Tj-Ti>0,0<j<n&&j!=i有解。
即(Aj-Ai)*x+(Bj-Bi)*y+(Cj-Ci)*z>0,0<j<n&&j!=i有解。
由于 z > 0, 所以可以两边同时除以z,将x/z,y/z分别看成未知数x和y,这样就化三维为二维,可用半平面交判断是否存在解了,对每个人构造一次,求一次半平面交即可。
我用的是ZZY的I&S算法的模版,做的过程中要将A*x+B*y+C>0表示的半平面,转化成由两点组成的向量表示。
首先,所有的半平面保证符号一致, 然后根据A,B,C的正负构造向量,取每个向量的左边为半平面。

Accepted Code:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
const double eps = 1e-8;
const double inf = 1e10;
int u[MAXN], v[MAXN], w[MAXN];
typedef struct point {double x, y;
}vect;
struct line {vect p;point u, v;bool operator < (const line& s) const {return atan2(s.p.y, s.p.x) > atan2(p.y, p.x);}
}Sline[MAXN];
vect operator - (const point a, const point b) {return (vect){a.x - b.x, a.y - b.y};
}
int pnz(double x) {return x < -eps ? -1 : x > eps ? 1 : 0;
}
double Cross(const vect a, const vect b) {return a.x * b.y - a.y * b.x;
}
bool Onleft(const point p, const line l) {return pnz(Cross(l.p, p - l.u)) > 0;
}
point Inter(const line a, const line b) {double t = Cross(b.p, a.u - b.u) / Cross(a.p, b.p);return (point){a.u.x + t * a.p.x, a.u.y + t * a.p.y};
}
bool Halfplane(int n) {sort(Sline, Sline + n);point Spt[n];int Q[n] = {0};int l = 0, r = 0;for (int i = 1; i < n; i++) {while (l < r && !Onleft(Spt[r - 1], Sline[i]))r--;while (l < r && !Onleft(Spt[l], Sline[i]))l++;Q[++r] = i;if (!pnz(Cross(Sline[i].p, Sline[Q[r - 1]].p))) {r--;if (Onleft(Sline[i].u, Sline[Q[r]]))Q[r] = i;}else Spt[r - 1] = Inter(Sline[Q[r]], Sline[Q[r - 1]]);}while (l < r && !Onleft(Spt[r - 1], Sline[Q[l]]))r--;while (l < r && !Onleft(Spt[l], Sline[Q[r]]))l++;if (r - l <= 1)return false;return true;
}
int main() {int t, n;double a, b, c;point s, e, p[4];p[0] = (point){0, 0};p[1] = (point){inf, 0};p[2] = (point){inf, inf};p[3] = (point){0, inf};scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%d%d%d", &u[i], &v[i], &w[i]);for (int i = 0; i < n; i++) {for (int j = 0; j < 4; j++) {int k = (j + 1) % 4;Sline[j] = (line){p[k] - p[j], p[j], p[k]};}int k = 4;bool tmp = false;for (int j = 0; j < n; j++) {if (i != j) {a = 1.0 * (u[i] - u[j]) / (u[i] * u[j]);b = 1.0 * (v[i] - v[j]) / (v[i] * v[j]);c = 1.0 * (w[i] - w[j]) / (w[i] * w[j]);if (pnz(a)) {if (pnz(b))s = (point){0, -c / b}, e = (point){pnz(b), -(a * pnz(b) + c) / b};else s = (point){-c / a, 0}, e = (point){-c / a, -pnz(a)};}else {if (pnz(b))s = (point){0, -c / b}, e = (point){pnz(b), -c / b};else {if (pnz(c) > 0)continue;tmp = true;break;}}Sline[k++] = (line){e - s, s, e};}}if (!tmp && Halfplane(k))printf("Yes\n");else printf("No\n");}if (t)printf("\n");}return 0;
}

ZOJ - Triathlon(线性规划+半平面交)相关推荐

  1. poj 1755 Triathlon (半平面交解一元二次不等式)(切割求半平面交)

    题目链接:哆啦A梦传送门 参考链接:https://blog.csdn.net/acm_cxlove/article/details/7883370 半平面交模板 题目:铁人三项,每个人在某一项中有确 ...

  2. POJ 1755 Triathlon(半平面交)

    题目链接:http://poj.org/problem?id=1755 题意:一段距离总长度为L,将L分成三部分a,b和c(a.b.c均大于0).有N(1 <= N <= 100) 个人, ...

  3. LA 2218 (半平面交) Triathlon

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

  4. 半平面交练习(计算几何)

    四:半平面交 Rotating Scoreboard /*Author : lifehappy */ #include <cstdio> #include <cmath> #i ...

  5. 模板:半平面交(计算几何)

    所谓半平面交,就是和"半平先生"当面交谈.顾名思义,这是一个源于日本的算法. (逃) 前言 感觉应用很灵活的一个算法,一切有两个变量的线性规划问题都可以转化为半平面交. 有时可能要 ...

  6. UVA1396 Most Distant Point from the Sea(AM - ICPC - Tokyo - 2007)(计算几何,半平面交 + 二分答案)

    整理的算法模板合集: ACM模板 题目传送门 见<训练指南>P279 很明显就是一个二分答案,它问的是最远的点,直接枚举因为这里都是double类型的数所以有无限个点,我们可以直接二分. ...

  7. POJ 1474 Video Surveillance(半平面交)

    题意:半平面交求多边形内核(我明明及的我之前是会用kuangbin第一份版平面交的,现在怎么就不会用了呢,补第二份代码) 代码: #include<cstdio> #include< ...

  8. POJ3335(半平面交)

    POJ3335 半平面交裸题 //poj3335 #include <cstdio> #include <cmath> #include <algorithm> # ...

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

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

  10. [BZOJ1007](HNOI2008)水平可见直线(半平面交习题)

    Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的.     例如,对于直线:   ...

最新文章

  1. 安妮宝贝的50句经典语句
  2. 3DSlicer相关资料汇总
  3. Office365----Project Online SKUs Change
  4. hadoop安装与配置
  5. 如何确认虚拟机被哪台主机锁定以及如何解锁
  6. Python学习二:词典基础详解
  7. 类似GoogleMap地图网站的简单实现(1)
  8. [渝粤教育] 重庆电子工程职业学院 信息技术与人工智能基础 参考 资料
  9. WSL:ssh 本地与阿里云数据交互
  10. python 杨辉三角居中打印_利用python打印杨辉三角
  11. 独家专访阿里云存储负责人吴结生:我经历的三个重大决策
  12. 利用matlab来设计FIR滤波器参数
  13. Fengshui(双向bfs看风水···)
  14. windows如何截图
  15. 电动牙刷也有国产黑马,竟然比千元大牌还厉害 | 钛空实测
  16. 虚拟同步发电机_学术简报基于分散式微电网的虚拟同步发电机无通信预同步并网方案...
  17. python info函数的使用方法_sysinfo函数使用方法
  18. html 微信登陆,登录包含微信登录.html
  19. [hive]return code -101 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. GC overhead limit exceeded
  20. 从appstore快速安装Xcode 8.0_如何解决xcode8安装慢的问题

热门文章

  1. CVPR2021:Found a Reason for me? Weakly-supervised Grounded Visual Question Answering using Capsules
  2. 31个全网最常用python实现(体系学习,学完显著提高代码复用能力)
  3. 关键词抓取规则,关键词标题SEO技巧
  4. 在c# winform 的 monthCalendar 里粗体凸显有数据的日期
  5. java来电_java串口 来电显示
  6. 影响世界的100条管理励志名言
  7. 大学生破译周鸿祎手机号 李开复放“橄榄枝”
  8. 图像空间域分析之图像统计特征
  9. 使用js实现textarea文本域长度,限制输入字数并统计剩余输入字符数
  10. python 情感分析实例_使用python+机器学习方法进行情感分析(详细步骤)