沫沫最近在玩一个二维的射箭游戏,如下图 1 1 所示,这个游戏中的
输入文件第一行是一个正整数 N N ,表示一共有
输入保证 30% 的数据满足 N≤100 N ≤ 100 , 50% 的数据满足 N≤5000 N ≤ 5000 , 100% 的数据满足 N≤100000 N ≤ 100000 且给出的所有坐标不超过 109 10 9 。
仅包含一个整数,表示最多的通关数。
5
2 8 12
5 4 5
3 8 10
6 2 3
1 3 7
3
考虑一个抛物线 y=ax2+bx y = a x 2 + b x 对于一个靶子 x,y1,y2 x , y 1 , y 2 合法的条件:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define For(i, a, b) for (i = a; i <= b; i++)
using namespace std;
inline int read() {int res = 0; bool bo = 0; char c;while (((c = getchar()) < '0' || c > '9') && c != '-');if (c == '-') bo = 1; else res = c - 48;while ((c = getchar()) >= '0' && c <= '9')res = (res << 3) + (res << 1) + (c - 48);return bo ? ~res + 1 : res;
}
const int N = 214748; int n, tn;
struct cyx {double x, y;friend inline cyx operator + (cyx a, cyx b) {return (cyx) {a.x + b.x, a.y + b.y};}friend inline cyx operator - (cyx a, cyx b) {return (cyx) {b.x - a.x, b.y - a.y};}friend inline cyx operator * (cyx a, double b) {return (cyx) {a.x * b, a.y * b};}friend inline cyx operator / (cyx a, double b) {return (cyx) {a.x / b, a.y / b};}friend inline double operator * (cyx a, cyx b) {return a.x * b.y - a.y * b.x;}
};
struct pyz {cyx a, b; int id; double it; cyx o() {return a - b;}} a[N], b[N], q[N];
bool check(cyx a, pyz b) {return b.o() * (b.a - a) > 0;}
bool comp(pyz a, pyz b) {if (a.it != b.it) return a.it < b.it; return (a.a - b.a) * (a.a - b.b) > 0;
}
cyx weak(pyz x, pyz y) {double s1 = (x.a - y.b) * (x.a - y.a), s2 = (x.b - y.a) * (x.b - y.b);return x.a + x.o() * s1 / (s1 + s2);
}
bool lpf(cyx a, pyz b) {return (a - b.b) * (a - b.a) > 0;}
bool cyxisdalao(int mid) {int i, n = 0, H = 1, T = 2; For (i, 1, tn) if (b[i].id <= mid &&(!n || b[i].it > a[n].it)) a[++n] = b[i]; q[1] = a[1]; q[2] = a[2];For (i, 3, n) {while (H < T && lpf(weak(q[T - 1], q[T]), a[i])) T--;while (H < T && lpf(weak(q[H], q[H + 1]), a[i])) H++;q[++T] = a[i];}while (H < T && lpf(weak(q[T - 1], q[T]), q[H])) T--;return T - H > 1;
}
int main() {int i, x, y1, y2; n = read();b[++tn] = (pyz) {(cyx) {0, 0}, (cyx) {0, 1}, 0};b[++tn] = (pyz) {(cyx) {0, 0}, (cyx) {1, 0}, 0}; For (i, 1, n) {x = read(); y1 = read(); y2 = read();double x1 = 1.0 * y1 / x, x2 = 1.0 * y2 / x;b[++tn] = (pyz) {(cyx) {0, x1}, (cyx) {1, x1 - x}, i};b[++tn] = (pyz) {(cyx) {1, x2 - x}, (cyx) {0, x2}, i};}For (i, 1, tn) b[i].it = atan2(b[i].b.y - b[i].a.y, b[i].b.x - b[i].a.x);sort(b + 1, b + tn + 1, comp); int l = 1, r = n; while (l <= r) {int mid = l + r >> 1;if (cyxisdalao(mid)) l = mid + 1; else r = mid - 1;}cout << r << endl; return 0;
}
本文发布于:2024-02-03 02:37:18,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170689903648089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |