您的位置:首页 > 其它

POJ 1755 Triathlon BZOJ 3800 Saber VS Lancer 半平面交

2016-01-10 15:28 351 查看
还是很奇怪为什么删了2个solve()中的判断就WA了。

改了right函数还是WA。

#define FOR(i,j,k) for(i=j;i<=k;i++)
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int N = 128;
typedef long double ld;
struct Point {
ld x, y;
Point(){}
Point(ld _x, ld _y) : x(_x), y(_y) {}
Point operator +(const Point &b) const { return Point(x + b.x, y + b.y); }
Point operator -(const Point &b) const { return Point(x - b.x, y - b.y); }
ld operator *(const Point &b) const { return x * b.y - y * b.x; }
Point operator *(ld b) const { return Point(b * x, b * y); }
} poly
;

struct Line {
Point x, v;
ld ang;
Line(){}
Line(const Point &a, const Point &b) : x(a), v(b) {
ang = atan2(v.y, v.x);
}

bool operator <(const Line &b) const {
if (ang == b.ang) return v * (b.x - x) < 0;
return ang < b.ang;
}

bool operator ==(const Line &b) const { return ang == b.ang; }

Point intersection(const Line &b) {
Point u = x - b.x;
ld t = (b.v * u) / (v * b.v);
return x + v * t;
}
} lines
;

bool right(const Point &p, const Line &l) {
return l.v * (p - l.x) < 0;
}

int half_plane_intersection(Line l[], int n, Point poly[]) {
static Line q
;
sort(l + 1, l + n + 1);
n = unique(l + 1, l + n + 1) - (l + 1);
int f = 1, r = 0, m = 0;
q[++r] = l[1]; q[++r] = l[2];
for (int i = 3; i <= n; i++) {
while (f < r && right(q[r].intersection(q[r - 1]), l[i])) r--;
while (f < r && right(q[f].intersection(q[f + 1]), l[i])) f++;
q[++r] = l[i];
}
while (f < r && right(q[r].intersection(q[r - 1]), q[f])) r--;
while (f < r && right(q[f].intersection(q[f + 1]), q[r])) f++;
q[r + 1] = q[f];
for (int i = f; i <= r; i++)
poly[++m] = q[i].intersection(q[i + 1]);
return m;
}

bool solve(double *v, double *u, double *w, int n, int i) {
int j, line_num = 0;
FOR(j,1,n) if (i != j) {
if (v[i] <= v[j] && u[i] <= u[j] && w[i] <= w[j]) return false;
if (v[i] >= v[j] && u[i] >= u[j] && w[i] >= w[j]) continue;
ld a = (1 / v[j] - 1 / w[j]) - (1 / v[i] - 1 / w[i]);
ld b = (1 / u[j] - 1 / w[j]) - (1 / u[i] - 1 / w[i]);
ld c = 1 / w[j] - 1 / w[i];
lines[++line_num] = Line(fabs(a) > fabs(b) ? Point(-c / a, 0) : Point(0, -c / b), Point(b, -a));
}
lines[++line_num] = Line(Point(0, 0), Point(0, -1));
lines[++line_num] = Line(Point(0, 0), Point(1, 0));
lines[++line_num] = Line(Point(0, 1), Point(-1, 1));
int m = half_plane_intersection(lines, line_num, poly);
return m > 2;
}

int main() {
static double a
, b
, c
;
int n, i;
scanf("%d", &n);
FOR(i,1,n) scanf("%lf%lf%lf", &a[i], &b[i], &c[i]);
FOR(i,1,n) puts(solve(a, b, c, n, i) ? "Yes" : "No");
return 0;
}

Triathlon
Time
Limit:
 1000MS
 Memory Limit: 10000K
Total Submissions: 6322 Accepted: 1601
DescriptionTriathlon 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. 
InputThe first line of the input file 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.OutputFor every contestant write to the output file 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.Sample Input9
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 7Sample OutputYes
Yes
Yes
No
No
No
Yes
No
Yes

3800: Saber VS Lancer

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 52  Solved: 18
[Submit][Status][Discuss]

Description

铁人三项是一种运动项目,和字面意思一样,是让铁做的人(?)去做三个项目,必须连续完成,而且全程讲求速度。第一项是游泳,第二项是骑自行车,第三项是跑步。现在所有选手的三个项目的速度都是已知的。但是这次比赛中,裁判可以任意选择每一个项目的路程长度(假设没有一项长度为0)。但是这样显然会影响比赛排名……有时她会按某种方式选择,使得一些个别的选手能赢得竞赛。

Input

首行为运动员的人数N (1 ≤ N ≤ 100,80%的数据中n<=20),以下N行,每行含3个整数,Vi, Ui 和Wi (1 ≤ Vi, Ui, Wi ≤ 10000),用空格隔开,表示各人3个项目的速度。 

Output

对于每个运动员,都用一行输出,假如裁判以某种方式选择的路程会使得他赢(即第一个冲线,同时抵达不算赢),则输出“Yes”,否则输出“No”  。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: