QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535685#3139. Largest QuadrilateralThirvinWA 0ms3984kbC++173.5kb2024-08-28 13:23:572024-08-28 13:23:57

Judging History

This is the latest submission verdict.

  • [2024-08-28 13:23:57]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3984kb
  • [2024-08-28 13:23:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using pii = pair<int, int> ;
using ll = long long;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define F first
#define S second
template<typename T>
pair<T, T> operator-(pair<T, T> a, pair<T, T> b){
    return mp(a.F - b.F, a.S - b.S);
}

template<typename T>
T cross(pair<T, T> a, pair<T, T> b){
    return a.F * b.S - a.S * b.F;
}

template<typename T>
vector<pair<T, T>> getConvexHull(vector<pair<T, T>>& pnts){

    sort(pnts.begin(), pnts.end());

    vector<pair<T, T>> hull;

    for(int i = 0; i < 2; i++){
        int t = hull.size();
        for(pair<T, T> pnt : pnts){
            while(hull.size() - t >= 2 && cross(hull.back() - hull[hull.size() - 2], pnt - hull[hull.size() - 2]) <= 0)
                hull.pop_back();
            hull.pb(pnt);
        }
        hull.pop_back();
        reverse(pnts.begin(), pnts.end());
    }

    return hull;
}

ld dis(pii x, pii s, pii e){
    pii v1 = pii(x.F - s.F, x.S - s.S);
    pii v2 = pii(e.F - s.F, e.S - s.S);

    ld c1 = abs(v1.F * v2.S - v1.S * v2.F);

//    ld c2 = v2.F * v2.F + v2.S * v2.S;

    return c1 ;
}

void solve(){
    int n;
    cin >> n;
    vector<pii> pnts(n);
    
    for(auto &it : pnts){
        cin >> it.F >> it.S;
    }

    vector<pii> hull = getConvexHull(pnts);
    n = hull.size();
    ld ans = 0;
    if(n == 3){
        ans = dis(hull[0], hull[1], hull[2]);
        ld mi = 1e9;
        for(auto it : pnts){
            if(it == hull[0] || it == hull[1] || it == hull[2])
                continue;
            for(int i = 0;i < 3;i ++){
                for(int j = i+1;j < 3;j ++){
                    mi = min(mi, dis(it, hull[i], hull[j]));
                }
            }

        }
        cout << (ans - mi) / 2 << "\n";
        return ;
    }
    for(int i = 0;i < n;i ++){
        for(int j = i + 2;j < n;j ++){
            ld lens = 0;
            {
                ld dx = hull[i].F - hull[j].F;
                ld dy = hull[i].S - hull[j].S;
                lens = sqrt(dx * dx + dy * dy);
            }
            ld h1 = 0;
            {
                int l = i, r = j;
                while(r - l > 1){
                    int m1 = (l + r) / 2;
                    int m2 = (r + m1) / 2;

                    if(dis(hull[m2], hull[i], hull[j]) > dis(hull[m1], hull[i], hull[j])){
                        r = m2;
                        h1 = max(h1, dis(hull[m2], hull[i], hull[j]));
                    } else {
                        h1 = max(h1, dis(hull[m1], hull[i], hull[j]));
                        l = m1;
                    }

                }

            }
            ld h2 = 0;
            {
                int l = j, r = n + i;
                while(r - l > 1){
                    int m1 = (l + r) / 2;
                    int m2 = (r + m1) / 2;

                    if(dis(hull[m2%n], hull[i], hull[j]) > dis(hull[m1%n], hull[i], hull[j])){
                        r = m2;
                        h2 = max(h2, dis(hull[m2%n], hull[i], hull[j]));
                    } else {
                        h2 = max(h2, dis(hull[m1%n], hull[i], hull[j]));
                        l = m1;
                    }

                }

            }
            ans = max(ans, h1  / 2 + h2 / 2); 

        }
    }
    cout  << ans << "\n";
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
	cin >> t;
	while(t --){
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3820kb

input:

3
5
0 0
1 0
3 1
1 2
0 1
4
0 0
4 0
0 4
1 1
4
0 0
1 1
2 2
1 1

output:

3
6
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3984kb

input:

1
4
0 0
1 0
0 1
3 2

output:

2.5

result:

ok single line: '2.5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3
4
0 0
0 0
0 0
0 0
5
0 0
1 0
3 1
1 2
0 1
4
0 0
4 0
0 4
1 1

output:

0
3
6

result:

ok 3 lines

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3984kb

input:

3
4
0 0
1 1
2 2
1 1
5
0 0
3 3
1 1
4 4
2 2
6
0 0
0 4
4 0
0 0
1 1
1 2

output:

0
0
6

result:

wrong answer 3rd lines differ - expected: '8', found: '6'