QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#354717 | #4368. Oil | igor_the_creator | WA | 280ms | 3832kb | C++17 | 5.4kb | 2024-03-15 21:43:03 | 2024-03-15 21:43:05 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;
typedef double db;
const int N = 2e3 + 5;
const int Mod = 998244353;
const int INF = 1e18;
const db EPS = 0;
// 精度、符号:
inline int sign(db a) { return a < -EPS ? -1 : a > EPS;}
inline int cmp(db a, db b) { return sign(a - b);}
// 点类:
struct P{
db x, y;
P () {};
P (db _x, db _y) : x(_x), y(_y) {}
P operator + (P p) {return {x + p.x, y + p.y};}
P operator - (P p) {return {x - p.x, y - p.y};}
P operator * (db d) {return {x * d, y * d};}
P operator / (db d) {return {x / d, y / d};}
bool operator < (P p) const { // ?: 0, 1e-9, 2e-9...
int c = cmp(x, p.x);
if (c) return c == -1;
return cmp(y, p.y) == -1;
}
bool operator == (P o) const {
return cmp(x, o.x) == 0 && cmp(y, o.y) == 0;
}
db dot(P p) {return x * p.x + y * p.y;} // 点积
db det(P p) {return x * p.y - y * p.x;} // 叉积
db distTo(P p) {return (*this - p).abs();}
db alpha() {return atan2(y, x);} // 范围:[-pai, pai]
// 反正切值,极角,long double 用 atan2l() ,三角函数比较慢
void read() {cin >> x >> y;}
void write() {cout << "(" << x << "," << y << ")" << "\n";}
db abs() {return sqrt(abs2());}
db abs2() {return x * x + y * y;}
int quad() const {return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0);}
// 判断在上半边还是下半边
P rot90() {return P{-y, x};} // 逆时针旋转90度
P unit() {return *this/abs();} // 单位向量
P rot(db an) {return {x * cos(an) - y * sin(an), x * sin(an) + y * cos(an)};}
// 逆时针转an度, (x+yi)(cos0+sin0i)
};
#define cross(p1, p2, p3) ((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y))
// = p1p2 x p1p3 = (p2 - p1) x (p3 - p1) (叉乘)
#define crossOp(p1, p2, p3) sign(cross(p1, p2, p3)) // 求叉乘符号
// >0 : 三点乘逆时针, =0:三点共线,<0:顺时针
bool chkLL(P p1, P p2, P q1, P q2) // 直线p、q是否恰有一个交点
{
db s1 = cross(q1, q2, p1), s2 = -cross(q1, q2, p2);
return sign(s1 + s2) != 0;
}
P isLL(P p1, P p2, P q1, P q2) // 求出两条直线的交点
{
db s1 = cross(q1, q2, p1), s2 = -cross(q1, q2, p2);
return (p1 * s2 + p2 * s1) / (s1 + s2);
}
bool intersect(db l1, db r1, db l2, db r2) // 判断区间[l1,r1]和[l2,r2]是否相交
{
if (l1 > r1) swap(l1, r1); if (l2 > r2) swap(l2, r2);
return !(cmp(r1, l2) == -1 || cmp(r2, l1) == -1);
}
bool isSS(P p1, P p2, P q1, P q2) // 线段相交(有公共点就行)
{
return intersect(p1.x, p2.x, q1.x, q2.x) && intersect(p1.y, p2.y, q1.y, q2.y) &&
crossOp(p1, p2, q1) * crossOp(p1, p2, q2) <= 0 && crossOp(q1, q2, p1) * crossOp(q1, q2, p2) <= 0;
}
bool isSS_strict(P p1, P p2, P q1, P q2) // 线段严格相交('x'只有一个公共点且不是端点)
{
return crossOp(p1, p2, q1) * crossOp(p1, p2, q2) < 0 && crossOp(q1, q2, p1) * crossOp(q1, q2, p2) < 0;
}
bool isMiddle(db a, db m, db b) // m是否在ab之间
{
return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}
bool isMiddle(P a, P m, P b) // 点m是否在ab之间
{
return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
}
bool onSeg(P p1, P p2, P q) // 点q是否在线段p1p2上
{
return crossOp(p1, p2, q) == 0 && isMiddle(p1, q, p2);
// crossOp容易有精度问题...
}
bool onSeg_strict(P p1, P p2, P q) // 严格版,点积判方向
{
return crossOp(p1, p2, q) == 0 && sign((q - p1).dot(p1 - p2)) * sign((q - p2).dot(p1 - p2)) < 0;
}
P proj(P p1, P p2, P q) // 求q到直线p1p2的投影(垂足) attention: p1!=p2
{
P dir = p2 - p1;
return p1 + dir * (dir.dot(q - p1) / dir.abs2());
}
P reflect(P p1, P p2, P q) // 求q以p1p2为轴的反射
{
return proj(p1, p2, q) * 2ll - q;
}
db nearest(P p1, P p2, P q) // 求q到p1p2的最小距离
{
if (p1 == p2) return p1.distTo(q);
P h = proj(p1, p2, q);
if (isMiddle(p1, h, p2)) return q.distTo(h);
return min(p1.distTo(q), p2.distTo(q));
}
db disSS(P p1, P p2, P q1, P q2) // 求两条线段的距离
{
if (isSS(p1, p2, q1, q2)) return 0;
return min({nearest(p1, p2, q1), nearest(p1, p2, q2), nearest(q1, q2, p1), nearest(q1, q2, p2)});
}
int n;
struct L{
P l, r;
int w;
}d[N];
int work(P p)
{
vector<pair<P, int>> cnt;
for (int i = 1; i <= n; ++i) {
if (d[i].l.y == p.y) continue;
P p1 = d[i].l - p, p2 = d[i].r - p;
if (d[i].l.y > p.y) {
cnt.pb({p1, -d[i].w});
cnt.pb({p2, d[i].w});
}
else {
cnt.pb({p1 * (-1), -d[i].w});
cnt.pb({p2 * (-1), d[i].w});
}
}
sort(cnt.begin(), cnt.end(), [&](pair<P, int> &a, pair<P, int> &b) {
db q = a.fi.det(b.fi);
if (q) return q > 0;
return a.se > b.se;
});
int ans = 0, now = 0;
for (auto i: cnt) {
now += i.se;
ans = max(ans, now);
}
return ans;
}
void solve()
{
int xl, xr, y;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> xl >> xr >> y;
if (xl > xr) swap(xl, xr);
d[i].l = P(xl, y);
d[i].r = P(xr, y);
d[i].w = xr - xl;
}
int ans = 0;
for (int i = 1; i <= n; ++i)
ans = max({ans, work(d[i].l) + d[i].w, work(d[i].r) + d[i].w});
cout << ans << "\n";
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
/*
5
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
5 100 180 20 30 60 30 70 110 40 10 40 50 0 80 70
output:
200
result:
ok single line: '200'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
3 50 60 10 -42 -42 20 25 0 10
output:
25
result:
ok single line: '25'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 -100 180 20
output:
280
result:
ok single line: '280'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
1 -1000000 1000000 1
output:
2000000
result:
ok single line: '2000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1 -1000000 1000000 1000000
output:
2000000
result:
ok single line: '2000000'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
1 -1000000 -999999 1000000
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
1 1000000 999999 1000000
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 -1000 0 200 1 1000 200
output:
1000
result:
ok single line: '1000'
Test #9:
score: -100
Wrong Answer
time: 280ms
memory: 3580kb
input:
1000 737368 429284 959063 -548693 513523 43074 243164 -465669 860567 422975 -244747 588631 -136535 -470055 501433 -580596 -269833 22422 476738 -448258 866889 358773 563858 950905 -923261 208187 66835 -295330 444422 360513 -903435 841952 491761 377801 520064 65247 479135 -307498 426574 -794533 -46924...
output:
485034187
result:
wrong answer 1st lines differ - expected: '490622362', found: '485034187'