Pagini recente » Cod sursa (job #2479873) | Cod sursa (job #2725801) | Cod sursa (job #2200228) | Cod sursa (job #901607) | Cod sursa (job #1863608)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 600;
const double PI = acos(-1);
int N;
int A[NMAX][2 * NMAX];
int val[2 * NMAX];
struct Point {
int x, y;
Point(int x = 0, int y = 0):
x(x), y(y) {
}
static int crossProduct(const Point &A, const Point &B, const Point &C) {
return A.x * B.y + B.x * C.y + C.x * A.y - C.x * B.y - A.x * C.y - B.x * A.y;
}
bool operator<(const Point &rhs) const {
return crossProduct(Point(), *this, rhs) > 0;
}
} arrPoints[2 * NMAX], bisPoints[2 * NMAX];
pair<Point, Point> lineSegment[NMAX];
bool lineSegmentIntersect(Point A, pair<Point, Point> B) {
return Point::crossProduct(Point(), A, B.first) * Point::crossProduct(Point(), A, B.second) <= 0;
}
int main() {
assert(freopen("laser.in", "r", stdin));
assert(freopen("laser.out", "w", stdout));
int i, j, k, l;
cin >> N;
for (i = 1; i <= N; ++i) {
int a, b, c, d;
cin >> a >> b >> c >> d;
lineSegment[i] = {Point(a * 2, b * 2), Point(c * 2, d * 2)};
arrPoints[2 * i - 1] = lineSegment[i].first;
arrPoints[2 * i] = lineSegment[i].second;
}
for (i = 1; i <= N; ++i)
cin >> A[i][2 * N + 1];
sort(arrPoints + 1, arrPoints + 2 * N + 1);
arrPoints[2 * N + 1] = arrPoints[1];
for (i = 1; i <= 2 * N; ++i)
bisPoints[i] = {(arrPoints[i].x + arrPoints[i + 1].x) / 2, (arrPoints[i].y + arrPoints[i + 1].y) / 2};
for (i = 1; i <= N; ++i)
for (j = 1; j <= 2 * N; ++j)
if (lineSegmentIntersect(bisPoints[j], lineSegment[i]))
A[i][j] = 1;
i = j = 1;
while (i <= N && j <= 2 * N) {
for (k = i; A[k][j] == 0 && k <= N; ++k);
--k;
if (!A[k][j]) {
++j;
continue;
}
if (k != i)
for (l = 1; l <= 2 * N; ++l)
swap(A[i][l], A[k][l]);
for (k = i + 1; k <= N; ++k)
if (A[k][j])
for (l = j; l <= 2 * N; ++l) {
A[k][l] -= A[i][l];
if (A[k][l] < 0)
A[k][l] += 2;
}
++i, ++j;
}
for (i = N; i >= 1; --i) {
int value = A[i][2 * N + 1];
int pos = -1;
for (j = 2 * N; j >= 1; --j) {
value -= A[i][j] * val[j];
if (A[i][j])
pos = j;
}
val[pos] = (value % 2 + 2) % 2;
}
int answer = 0;
for (i = 1; i <= 2 * N; ++i)
answer += val[i] > 0;
cout << answer << '\n';
cout << fixed << setprecision(6);
for (i = 1; i <= 2 * N; ++i) {
if (val[i] == 0)
continue;
double res = atan2(bisPoints[i].y, bisPoints[i].x) * 180 / PI;
if (res < 0)
res += 360;
cout << res << '\n';
}
return 0;
}