QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#535776 | #3139. Largest Quadrilateral | Thirvin | AC ✓ | 458ms | 4048kb | C++17 | 2.8kb | 2024-08-28 14:37:03 | 2024-08-28 14:37:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ld = long long;
using ll = long long;
using pii = pair<ld, ld> ;
#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);
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 ++){
int l1 = i+1;
int l2 = i+3;
for(int j = i + 2;j < n;j ++){
while((l1+1)%n != j && dis(hull[l1], hull[i], hull[j]) < dis(hull[(l1+1)%n], hull[i], hull[j])){
l1 += 1;
l1 %= n;
}
while((l2+1)%n != i && dis(hull[l2], hull[i], hull[j]) < dis(hull[(l2+1)%n], hull[i], hull[j])){
l2 += 1;
l2 %= n;
}
ans = max(dis(hull[l1], hull[i], hull[j]) + dis(hull[l2], hull[i], hull[j]), ans);
}
}
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: 3528kb
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: 3620kb
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: 3616kb
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: 3544kb
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: 3920kb
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: 458ms
memory: 4048kb
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