版本比较
题解:P3738 [HAOI2014] 穿越封锁线
正文
增加 7 行删除 7 行
64 行未改动656667686969707172737475767778787980818283848586878888899091929393949596979898991001011011021031041051061061071081091103 行未改动64 行未改动int main(){ cin >> n; for (int i = 1; i <= n; i ++ ) cin >> a[i].x >> a[i].y; cin >> sx >> sy;
for (int i = 1; i <= n; i ++ ){ if (a[i].x != sx) continue; int pre = (i == 1 ? n : i - 1); int nxt = (i == n ? 1 : i + 1); if ((a[pre].x <= sx && a[nxt].x <= sx) || (a[pre].x >= sx && a[nxt].x >= sx)) jd[i] = true; if (a[pre].x == sx && a[nxt].x > sx) jd[i] ^= 1; if (a[nxt].x == sx && a[pre].x > sx) jd[i] ^= 1; }
int m = 0; for (int i = 1; i <= n; i ++ ){ int j = i % n + 1; if (a[i].x == sx){ if (!jd[i]) y[++ m] = a[i].y; } if (a[i].x == a[j].x) continue; if ((a[i].x < sx && sx < a[j].x) || (a[j].x < sx && sx < a[i].x)) y[++ m] = get_y(a[i], a[j], sx); }
sort(y + 1, y + m + 1);
int j = 1; while (j <= m && y[j] < sy) j ++;
if (j > m){ cout << "0\n"; return 0; }
double ans = 0; if (j % 2 == 0) ans += y[j] - sy, j ++ ;
while (j <= m){ ans += y[j + 1] - y[j]; j += 2; }
cout << (int)ans << "\n"; // cout << fixed << setprecision(0) << ans << "\n";}```3 行未改动