QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535805#3139. Largest QuadrilateralThirvinAC ✓2954ms4096kbC++173.8kb2024-08-28 15:00:252024-08-28 15:00:29

Judging History

This is the latest submission verdict.

  • [2024-08-28 15:00:29]
  • Judged
  • Verdict: AC
  • Time: 2954ms
  • Memory: 4096kb
  • [2024-08-28 15:00:25]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ld = long long;
using pii = pair<ld, ld> ;
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);
    
    map<pii, int> cnt;
    for(auto &it : pnts){
        cin >> it.F >> it.S;
        cnt[it] += 1;
    }
    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] && cnt[it] == 1) || (it == hull[1] && cnt[it] == 1) || (it == hull[2] && cnt[it] == 1))
                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]));
                }
            }

        }
        ans -= mi;
        if(ans % 2){
            cout << ans/2 << ".5\n";
        } else {
            cout << ans/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;
                int cnt = 12;
                while(cnt --){
                    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])){
                        l = m1;
                        h1 = max(h1, dis(hull[m2], hull[i], hull[j]));
                    } else {
                        h1 = max(h1, dis(hull[m1], hull[i], hull[j]));
                        r = m2;
                    }

                }

            }
            ld h2 = 0;
            {
                int l = j, r = n + i;
                int cnt = 12;
                while(cnt --){
                    int m1 = (l + r) / 2;
                    int m2 = (l + m1) / 2;
                   
                    if(dis(hull[m2%n], hull[i], hull[j]) > dis(hull[m1%n], hull[i], hull[j])){
                        r = m1;
                        h2 = max(h2, dis(hull[m2%n], hull[i], hull[j]));
                    } else {
                        h2 = max(h2, dis(hull[m1%n], hull[i], hull[j]));
                        l = m2;
                    }

                }

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

        }
    }
    if(ans % 2){
        cout << ans/2 << ".5" << "\n";
    } else {
        cout << ans/2 << "\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: 3776kb

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: 3504kb

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: 3620kb

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: 0
Accepted
time: 0ms
memory: 3508kb

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
8

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 2ms
memory: 3832kb

input:

3
6
0 0
8 8
7 9
6 9
5 8
0 99
29
999891293 708205
369022896 771
993004062 999827531
929592437 29458
994968624 999539287
569046020 1943
2200 986643253
11189 5792636
712825 999917190
2482686 272282
43058 665660
10373878 31825
508452623 112
3304 269412577
43817590 3789
999996618 957802194
999902626 9749...

output:

388
996775018731291724.5
965005706567704502.5

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 2954ms
memory: 4096kb

input:

3
4096
53819837 441491349
842988334 208694314
834815184 199336081
754579314 871065186
798603871 163346278
881287987 261003199
69176974 629967383
167500703 196776949
934427498 382642646
949669136 517253054
205028216 839840619
904403509 697377307
909983630 685508552
106436006 718191161
704172704 90101...

output:

405000001187842381
405000001187842381
405000001187842381

result:

ok 3 lines