难度:4
知识点:模拟
这道题一开始看见数据范围是10的5次方,怎么都想不起来好的做法,一看题解,这道题可以n的平方过,索性就去写了,注意模拟的细节即可,后来想了想也不知道有什么好的贪心优化的方法,就是按照线段的高低排位,可能有那么一点用,但是也完全不是线性扫描,就这样把
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
const int N = 1e5 + 5;
struct line {
double x1, y1, x2, y2;
} l[N];
int main() {
int n;
double sx;
double sy = 1000000000;
cin >> n >> sx;
for (int i = 0; i < n; i++) {
cin >> l[i].x1 >> l[i].y1 >> l[i].x2 >> l[i].y2;
}
while (1) {
int ok = 0;
double Max = -10000000000;
int rec;
for (int i = 0; i < n; i++) {
double y = (sx - l[i].x1) * (l[i].y1 - l[i].y2) / (l[i].x1 - l[i].x2) + l[i].y1;
if (y > sy || sx <= min(l[i].x1, l[i].x2) || sx >= max(l[i].x1, l[i].x2)) continue;
ok = 1;
if (y > Max) { Max = y; rec = i; }
}
if (!ok) break;
if (l[rec].y1 < l[rec].y2) { sx = l[rec].x1; sy = l[rec].y1; }
else { sx = l[rec].x2; sy = l[rec].y2; }
}
printf("%d", (int) sx);
return 0;
}