QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#810219#3139. Largest QuadrilateralSGColinCompile Error//Python33.1kb2024-12-11 20:28:142024-12-11 20:28:22

Judging History

This is the latest submission verdict.

  • [2024-12-11 20:28:22]
  • Judged
  • [2024-12-11 20:28:14]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int rd() {
	int x = 0;
	bool f = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) f |= (c == '-');
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return f ? -x : x;
}

#define N 5007

struct Vec { 
    ll x, y, id;
    ll norm() {return x * x + y * y;}
    ll len() {return sqrt(norm());}
    Vec operator + (const Vec &obj) {return (Vec){x + obj.x, y + obj.y};} 
    Vec operator - (const Vec &obj) {return (Vec){x - obj.x, y - obj.y};} 
    Vec operator * (const ll &t) {return (Vec){x * t, y * t};}
    ll operator * (const Vec &obj) {return x * obj.x + y * obj.y;} 
    ll cross (const Vec &obj) {return x * obj.y - y * obj.x;}
    ll dis(const Vec &obj) {return ((*this) - obj).len();}
    ll dis2(const Vec &obj) {return ((*this) - obj).norm();}
    inline bool operator < (const Vec &obj) const{
        return x == obj.x ? y < obj.y : x < obj.x;
    }
    inline bool operator != (const Vec &obj) const{
    	return x != obj.x || y != obj.y || id != obj.id;
	}
} p[N], s[N];

inline bool cmp(Vec a, Vec b) {
    ll d = (a - p[1]).cross(b - p[1]);
    return d == 0 ? a.dis2(p[1]) < b.dis2(p[1]) : d > 0;
}

inline ll labs(ll x) {
	return x > 0 ? x : -x;
}

inline ll sz(Vec a, Vec b, Vec c) {
	return labs(a.cross(b) + b.cross(c) + c.cross(a));
}

inline ll sz(Vec a, Vec b, Vec c, Vec d) {
	return labs(a.cross(b) + b.cross(c) + c.cross(d) + d.cross(a));
}

#define nxt(x) (((x) + 1) % n)

inline void work() {
    int n = rd();
    for (int i = 1; i <= n; ++i) {
    	p[i].x = rd(); p[i].y = rd(); p[i].id = i;
        if (p[i] < p[1]) swap(p[1], p[i]);
    }
    sort(p + 2, p + 1 + n, cmp);
    int top = 1;
    s[0] = p[1]; s[1] = p[2];
    for (int i = 3; i <= n; ++i) {
        for (; top && (s[top] - s[top - 1]).cross(p[i] - s[top - 1]) < 0; --top);
        s[++top] = p[i];
    }
    if (top < 2) {puts("0"); return;}
	if (top == 2) {
		ll totsz = sz(s[0], s[1], s[2]), ans = 0;
		for (int i = 1; i <= n; ++i)
			if (p[i] != s[0] && p[i] != s[1] && p[i] != s[2]) {
				ll tmp = min(min(sz(s[0], s[1], p[i]), sz(s[0], s[2], p[i])), sz(s[1], s[2], p[i]));
				ans = max(ans, totsz - tmp);
			}
		printf("%lld", ans / 2);
		puts((ans & 1) ? ".5" : ""); return;
	} 
	n = top + 1;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
    	int ptr1 = (i + 1) % n;
    	int ptr2 = (i + 3) % n;
    	for (int j = i + 2; j < n - (i == 0); ++j) {
    		if (ptr1 == i) ptr1 = nxt(ptr1);
    		if (ptr2 == j) ptr2 = nxt(ptr2);
    		for (; sz(s[i], s[j], s[nxt(ptr1)]) > sz(s[i], s[j], s[ptr1]); ) {
    			ptr1 = nxt(ptr1);
    			if (ptr1 == j) {ptr1 = (ptr1 - 1 + n) % n; break;}
			}
    		for (; sz(s[i], s[j], s[nxt(ptr2)]) > sz(s[i], s[j], s[ptr2]); ) {
    			ptr2 = nxt(ptr2); 
    			if (ptr2 == i) {ptr2 = (ptr2 - 1 + n) % n; break;}
			}			
			ans = max(ans, sz(s[i], s[j], s[ptr1]) + sz(s[i], s[j], s[ptr2]));
		}
	}
	printf("%lld", ans / 2);
	puts((ans & 1) ? ".5" : ""); 
}

int main() {
	for (int t = rd(); t; --t) work();
	return 0;
}

詳細信息

  File "answer.code", line 2
    using namespace std;
          ^^^^^^^^^
SyntaxError: invalid syntax