Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <tuple>
- #include <algorithm>
- using namespace std;
- void setIO() {
- #ifndef EREKLE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- struct Point {
- int x, y;
- Point(int x0, int y0): x(x0), y(y0){}
- Point(){}
- };
- typedef pair<Point, Point> Slope;
- struct Command {
- int x, type;
- Slope slope;
- bool operator < (const Command &c2) const {
- return pair<int, int>(x, type) < pair<int, int>(c2.x, c2.type);
- }
- Command(int x2, int type2, Slope slope2): x(x2), type(type2), slope(slope2){}
- };
- int main() {
- setIO();
- int x = 0; // x value used to compare slopes
- auto higher = [&x](const Slope &s1, const Slope &s2) {
- double y1 = s1.first.y + (double)(s1.second.y - s1.first.y) * (x-s1.first.x)/(s1.second.x-s1.first.x);
- double y2 = s2.first.y + (double)(s2.second.y - s2.first.y) * (x-s2.first.x)/(s2.second.x-s2.first.x);
- return y1 > y2;
- };
- int n; cin >> n;
- vector<Command> commands; // x, type (0=start, 1=finish), slope
- Slope curSlope{{0, 0}, {0, 0}};
- for (int i = 0; i < n; ++i) {
- Slope s;
- cin >> s.first.x >> s.first.y >> s.second.x >> s.second.y;
- if (!s.first.x && !s.first.y) curSlope = s;
- commands.emplace_back(s.first.x, 0, s);
- commands.emplace_back(s.second.x, 1, s);
- }
- sort(commands.begin(), commands.end());
- int slopeCount = 1; // slopes traversed
- set<Slope, decltype(higher)> activeSlopes(higher);
- for (int ci = 0; ci < (int)commands.size(); ++ci) {
- Command &c = commands[ci];
- x = c.x;
- if (c.type == 0) {
- activeSlopes.insert(c.slope);
- } else {
- activeSlopes.erase(c.slope);
- if (ci+1 == (int)commands.size() || commands[ci+1].x > c.x) {
- if (curSlope.second.x == c.x) {
- set<Slope, decltype(higher)>::iterator it = activeSlopes.upper_bound(curSlope);
- if (it == activeSlopes.end()) break;
- curSlope = *it;
- ++slopeCount;
- }
- }
- }
- }
- cout << slopeCount << endl;
- cout << curSlope.second.x << ' ' << curSlope.second.y << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement