QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#535747 | #3139. Largest Quadrilateral | Thirvin | WA | 2ms | 3944kb | C++17 | 3.8kb | 2024-08-28 14:12:36 | 2024-08-28 14:12:37 |
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);
// 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;
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 + 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: 3560kb
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: 3708kb
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: 3788kb
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: 3588kb
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: -100
Wrong Answer
time: 2ms
memory: 3944kb
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 995147671211600464.5 944404336681674295.5
result:
wrong answer 2nd lines differ - expected: '996775018731291724.5', found: '995147671211600464.5'