forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10078.cpp
143 lines (135 loc) · 2.01 KB
/
10078.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <bits/stdc++.h>
using namespace std;
struct Point {int x, y;} ref_;
vector<Point> points;
const int infinity = 2147483647;
int flag;
int is_left_special(Point p0, Point p1, Point p2)
{
long long int cross_product = (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
if (cross_product > 0)
{
return 1;
}
else if (cross_product < 0)
{
return -1;
}
else
{
return 0;
}
}
bool is_left(Point p0, Point p1, Point p2)
{
long long int cross_product = (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
if (cross_product > 0)
{
return true;
}
else if (cross_product < 0)
{
return false;
}
else
{
if ((p0.x == p1.x) && (p0.y == p1.y))
{
return true;
}
else if ((p0.x == p2.x) && (p0.y == p2.y))
{
return false;
}
else
{
return false;
}
}
}
bool compare(Point p2, Point p1)
{
return !is_left(ref_, p1, p2);
}
void graham_scan()
{
stack<Point> final;
int i = 0;
int count = 0;
int n_vertex = points.size();
int left_flag;
if (i < n_vertex)
{
final.push(points[i]);
i++;
count++;
}
if (i < n_vertex)
{
final.push(points[i]);
i++;
count++;
}
Point p0, p1, p2;
while ((count <= n_vertex) && (count > 1))
{
p2 = points[i % n_vertex];
p1 = final.top();
final.pop();
p0 = final.top();
left_flag = is_left_special(p0, p1, p2);
if (left_flag >= 0)
{
final.push(p1);
final.push(p2);
i++;
count++;
}
else
{
flag = 0;
}
}
}
int main()
{
int n_vertex;
Point input;
while (cin >> n_vertex)
{
if (n_vertex == 0)
{
break;
}
int i = 0;
flag = 1;
ref_.x = infinity;
ref_.y = infinity;
points.clear();
while (i < n_vertex)
{
cin >> input.x >> input.y;
points.push_back(input);
if (input.y < ref_.y)
{
ref_ = input;
}
else if ((input.y == ref_.y) && (input.x < ref_.x))
{
ref_ = input;
}
i++;
}
sort(points.begin(), points.end(), compare);
graham_scan();
if (flag == 0)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}