booljudge(Vec v){ return (v - p[0] ^ v - p[1]) > 0; } } lines[N];
intsolve(const Vec& p){ int l = 0, r = n; while (l < r) { int mid = (l+r+1) >> 1; if (lines[mid].judge(p)) l = mid; else r = mid - 1; } return r; }
signedmain(){ int Y1, Y2, cnt = 0; while (scanf("%lld%lld%*d%lld%*d%lld", &n, &m, &Y1, &Y2), n) { if (cnt++) puts(""); for (int i = 0; i <= n; i++) ans[i] = 0, lines[i].p[0].y = Y1, lines[i].p[1].y = Y2; for (int i = 1; i <= n; i++) scanf("%lld%lld", &lines[i].p[0].x, &lines[i].p[1].x); for (int i = 1, x, y; i <= m; i++) scanf("%lld%lld", &x, &y), ans[solve({x, y})]++; for (int i = 0; i <= n; i++) printf("%lld: %lld\n", i, ans[i]); } return0; }
Segments
给 n 个线段,问是否存在一条直线满足所有线段在这条直线上的投影之间存在交点,如果 ∣a−b∣<10−8 认为 a=b。
boolcheck(Vector a, Vector b){ if (a == b) returnfalse; for (int i = 1; i <= n; i++) { int A = sgn((a - seg[i][0]) * (b - seg[i][0])); int B = sgn((a - seg[i][1]) * (b - seg[i][1])); if (A * B > 0) returnfalse; } returntrue; }
intmain(){ scanf("%d", &T); while (T--) { int k = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 0; j <= 1; j++, k++) { scanf("%lf%lf", &pnts[k].x, &pnts[k].y); seg[i][j] = pnts[k]; } } for (int i = 1; i <= k; i++) { for (int j = i+1; j <= k; j++) { if (check(pnts[i], pnts[j])) { puts("Yes!"); goto end; } } }