QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#736361 | #9520. Concave Hull | xsdgp | WA | 1ms | 3924kb | C++20 | 1.6kb | 2024-11-12 10:24:51 | 2024-11-12 10:24:51 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int n;
struct VECTOR
{
double x,y;
double operator^(const VECTOR &v)const
{
return x*v.y-y*v.x;
}
};
struct POINT
{
double x,y;
bool operator<(const POINT &p)const
{
if(x==p.x)return y<p.y;
else return x<p.x;
}
bool operator==(const POINT &p)const
{
return x==p.x&&y==p.y;
}
VECTOR operator-(const POINT &p)const
{
return {x-p.x,y-p.y};
}
}p[100005];
int cross(VECTOR v1,VECTOR v2)
{
return v1^v2;
}
vector<POINT> st;
int sub;
POINT p0;
bool check(POINT p)
{
POINT back1=st.back(),back2=*(st.rbegin()+1);
if(cross(back1-back2,p-back1)<=0)
{
if(cross(p-back1,back1-back2)<sub)
{
sub=cross(p-back1,back1-back2);
p0=back1;
}
return 1;
}
return 0;
}
void andrew()
{
st.clear();
sort(p+1,p+n+1);
for(int i=1;i<=n;i++)
{
while(st.size()>1&&check(p[i]))st.pop_back();
st.push_back(p[i]);
}
int k=st.size();
for(int i=n-1;i>=1;i--)
{
while(st.size()>k&&check(p[i]))st.pop_back();
st.push_back(p[i]);
}
st.pop_back();
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>p[i].x>>p[i].y;
sub=1e18;
p0={1e9+1,1e9+1};
andrew();
int area=0;
for(int i=0;i<st.size();i++)
{
POINT o={0,0};
VECTOR v=st[i]-o,v1=st[(i+1)%n]-o;
area+=cross(v,v1);
if(st[i]==p0)
{
cout<<-1<<endl;
return;
}
}
cout<<area-sub<<endl;;
}
signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)solve();
return 0;
}
/*
2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
input:
2 6 -2 0 1 -2 5 2 0 4 1 2 3 1 4 0 0 1 0 0 1 1 1
output:
40 -1
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3924kb
input:
10 243 -494423502 -591557038 -493438474 -648991734 -493289308 -656152126 -491185085 -661710614 -489063449 -666925265 -464265894 -709944049 -447472922 -737242534 -415977509 -773788538 -394263365 -797285016 -382728841 -807396819 -373481975 -814685302 -368242265 -818267002 -344482838 -833805545 -279398...
output:
2178418106972223301 -1 1651696708629782378 1884670113275845698 2119126281997959896 -1 2271190351049000367 1998643369369571220 1740678170179963016 -1
result:
wrong answer 1st lines differ - expected: '2178418010787347715', found: '2178418106972223301'