Section 5.2 5.3
parent
afa856ad18
commit
2367abf1b4
@ -0,0 +1,46 @@
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
const int N = int(1e4 + 5);
|
||||
struct point
|
||||
{
|
||||
int x, y;
|
||||
point() {}
|
||||
point(int _x, int _y) : x(_x), y(_y) {}
|
||||
}a[N], stk[N];
|
||||
inline point operator+(const point &L, const point &R) { return point(L.x + R.x, L.y + R.y); }
|
||||
inline point operator-(const point &L, const point &R) { return point(L.x - R.x, L.y - R.y); }
|
||||
inline int cross(const point &L, const point &R) { return L.x * R.y - L.y * R.x; }
|
||||
inline int dot(const point &L, const point &R) { return L.x * R.x + L.y * R.y; }
|
||||
inline int len2(const point &u, const point &v)
|
||||
{
|
||||
point p = u - v;
|
||||
return p.x * p.x + p.y * p.y;
|
||||
}
|
||||
inline bool cmp1(const point &L, const point &R) { return L.x < R.x || (L.x == R.x && L.y < R.y); }
|
||||
inline bool cmp2(const point &L, const point &R)
|
||||
{
|
||||
int det = cross(L - a[0], R - a[0]);
|
||||
return det != 0 ? det > 0: len2(L, a[0]) < len2(R, a[0]);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++)
|
||||
scanf("%d%d", &a[i].x, &a[i].y);
|
||||
std::swap(*std::min_element(a, a + n, cmp1), a[0]);
|
||||
std::sort(a + 1, a + n, cmp2);
|
||||
int top = 0;
|
||||
stk[top++] = a[0];
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
while (top >= 2 && cross(a[i] - stk[top - 1], stk[top - 1] - stk[top - 2]) >= 0) top--;
|
||||
stk[top++] = a[i];
|
||||
}
|
||||
stk[top] = stk[0];
|
||||
int res = 0;
|
||||
for (int i = 0; i < top; i++)
|
||||
res += cross(stk[i], stk[i + 1]);
|
||||
printf("%d", res / 100);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
const int N = int(1e4 + 5);
|
||||
struct point
|
||||
{
|
||||
int x, y;
|
||||
point() {}
|
||||
point(int _x, int _y) : x(_x), y(_y) {}
|
||||
}a[N], stk[N];
|
||||
inline point operator+(const point &L, const point &R)
|
||||
{ return point(L.x + R.x, L.y + R.y); }
|
||||
inline point operator-(const point &L, const point &R)
|
||||
{ return point(L.x - R.x, L.y - R.y); }
|
||||
inline int cross(const point &L, const point &R) { return L.x * R.y - L.y * R.x; }
|
||||
inline int dot(const point &L, const point &R) { return L.x * R.x + L.y * R.y; }
|
||||
inline int len2(const point &u, const point &v)
|
||||
{
|
||||
point p = u - v;
|
||||
return p.x * p.x + p.y * p.y;
|
||||
}
|
||||
inline bool cmp1(const point &L, const point &R)
|
||||
{ return L.x < R.x || (L.x == R.x && L.y < R.y); }
|
||||
inline bool cmp2(const point &L, const point &R)
|
||||
{
|
||||
int det = cross(L - a[0], R - a[0]);
|
||||
return det != 0 ? det > 0: len2(L, a[0]) < len2(R, a[0]);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++)
|
||||
scanf("%d%d", &a[i].x, &a[i].y);
|
||||
std::swap(*std::min_element(a, a + n, cmp1), a[0]);
|
||||
std::sort(a + 1, a + n, cmp2);
|
||||
int top = 0;
|
||||
stk[top++] = a[0];
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
while (top >= 2 && cross(a[i] - stk[top - 1], stk[top - 1] - stk[top - 2]) >= 0) top--;
|
||||
stk[top++] = a[i];
|
||||
}
|
||||
stk[top] = stk[0];
|
||||
int res = 0;
|
||||
for (int i = 0; i < top; i++)
|
||||
res += cross(stk[i], stk[i + 1]);
|
||||
printf("%d", res / 100);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
#include <cstdio>
|
||||
#define C const
|
||||
#define I inline
|
||||
struct P
|
||||
{
|
||||
int x, y;
|
||||
P() {}
|
||||
P(int _x, int _y) { x = _x, y = _y; }
|
||||
} a[105];
|
||||
I P operator+(C P &L, C P &R) { return P(L.x + R.x, L.y + R.y); }
|
||||
I P operator-(C P &L, C P &R) { return P(L.x - R.x, L.y - R.y); }
|
||||
I int cross(C P &L, C P &R) { return L.x * R.y - L.y * R.x; }
|
||||
I int dot(C P &L, C P &R) { return L.x * R.x + L.y * R.y; }
|
||||
I bool check(C P &p, C P &u, C P &v)
|
||||
{
|
||||
return cross(u - p, v - p) == 0 && dot(u - p, v - p) <= 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
for (int n, m, T = 1; (scanf("%d", &n), n) && scanf("%d", &m); T++)
|
||||
{
|
||||
if (T > 1) putchar('\n');
|
||||
printf("Problem %d:\n", T);
|
||||
for (int i = 0; i < n; i++)
|
||||
scanf("%d%d", &a[i].x, &a[i].y);
|
||||
a[n] = a[0];
|
||||
while (m--)
|
||||
{
|
||||
P p;
|
||||
scanf("%d%d", &p.x, &p.y);
|
||||
bool flag = false;
|
||||
int cnt = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (flag = check(p, a[i], a[i + 1])) break;
|
||||
int d1 = a[i].y - p.y, d2 = a[i + 1].y - p.y,
|
||||
d = cross(a[i] - p, a[i + 1] - p);
|
||||
cnt += (d >= 0 && d1 < 0 && d2 >= 0) || (d <= 0 && d1 >= 0 && d2 < 0);
|
||||
}
|
||||
puts(flag || (cnt & 1) ? "Within" : "Outside");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in new issue