QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649950 | #6436. Paimon Polygon | wangyue2017 | WA | 5ms | 10460kb | C++14 | 3.1kb | 2024-10-18 11:45:50 | 2024-10-18 11:45:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define D long double
#define int long long
#define P pair<int,int>
#define x first
#define y second
int cross(P a,P b){
return a.x*b.y-a.y*b.x;
}
P operator-(P a,P b){
return {a.x-b.x,a.y-b.y};
}
D dist(P a){
return sqrt(a.x*a.x+a.y*a.y);
}
const int N =1.1e6;
P a[N];
int sk[N],used[N];
int n;
D mx=0;
#define in(x) scanf("%lld",&x)
int hull(){
int top=0,bas=1;
sort(a+1,a+1+n);
for(int i=1;i<=n;++i){
if(used[i])continue;
while(top>bas&&cross(a[i]-a[sk[top-1]],a[sk[top]]-a[sk[top-1]])>=0)top--;
sk[++top]=i;
}
bas=top;
for(int i=n-1;i;--i){
if(used[i])continue;
while(top>bas&&cross(a[i]-a[sk[top-1]],a[sk[top]]-a[sk[top-1]])>=0)top--;
sk[++top]=i;
}
return top-1;
}
void cover(){
int t=hull();
D ans=0;
sk[t+1]=sk[1];
for(int i=1;i<=t;++i){
used[sk[i]]=1;
ans+=dist(a[sk[i]]-a[sk[i+1]]);
}
bool flag=1;
for(int i=1;i<=n;++i){
if(a[i]==(P){0,0}){
if(used[i]==0)
flag=0;
else used[i]=0;
}
}
int tt=hull();
if(t+tt!=n+1){
flag=0;
}
if(tt<=2)flag=0;
sk[tt+1]=sk[1];
for(int i=1;i<=tt;++i){
ans+=dist(a[sk[i]]-a[sk[i+1]]);
}
if(flag)mx=ans;
}
struct dot
{
int x,y;
D ang;
}b[N];
bool comp(dot a,dot b){
return a.ang<b.ang;
}
int L=1,R=0,c1,c2,n1,n2;
void rot(){
sort(b+1,b+1+n,comp);
D sm=0;
for(int i=1;i<=n;++i)a[i]={b[i].x,b[i].y};
for(int i=n+1;i<=2*n;++i)a[i]=a[i-n];
for(int i=1;i<n;++i)
if(cross(a[i+1],a[i])==0&&b[i+1].ang-b[i].ang<1e-9)return;
for(int i=1;i<=n;++i)sm+=dist(a[i+1]-a[i]);
L=1,R=1,c1=0,c2=0;
while(b[R+1].ang<=0)R++;
for(int i=1;i<=R;++i){
if(i+2<=R)if(cross(a[i+2]-a[i],a[i+1]-a[i])>=0)c1++;
}
for(int i=R+1;i<=L+n-1;++i){
if(i+2<=L+n-1)if(cross(a[i+2]-a[i],a[i+1]-a[i])>=0)c2++;
}
L=0;
n1=R+1;n2=n-n1;
while(L<=n){
L++;
n1--;n2++;
if(n1>=2)if(cross(a[L+1]-a[L-1],a[L]-a[L-1])>=0)c1--;
if(n2>=3)if(cross(a[L]-a[L-2+n],a[L-1+n]-a[L-2+n])>=0)c2++;
while(cross(a[L],a[R+1])>0){
R++;
n1++;n2--;
if(n1>=3)if(cross(a[R]-a[R-2],a[R-1]-a[R-2])>=0)c1++;
if(n2>=2)if(cross(a[R+2]-a[R],a[R+1]-a[R])>=0)c2--;
if(c1==0&&c2==0&&n1>=2&&n2>=2&&cross(a[R+1],a[L-1+n])>0){
mx=max(mx,sm-dist(a[L]-a[L-1+n])-dist(a[R]-a[R+1])+dist(a[L])+dist(a[L-1+n])+dist(a[R])+dist(a[R+1]));
}
}
}
}
signed main(){
int t;
cin>>t;
while(t--){
mx=0;
in(n);
for(int i=1;i<=n;++i)in(a[i].x),in(a[i].y);
for(int i=1;i<=n;++i)b[i].x=a[i].x,b[i].y=a[i].y,b[i].ang=atan2(b[i].y,b[i].x);
for(int i=1;i<=n+1;++i)used[i]=0;
a[++n]={0,0};
cover();
n--;
rot();
printf("%.10Lf\n",mx);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 10380kb
input:
3 4 0 3 3 0 2 3 3 2 5 4 0 5 -5 -4 -2 1 -2 -5 -2 4 0 1 1 0 0 2 1 1
output:
17.2111025509 36.6326947621 0.0000000000
result:
ok 3 numbers
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 10460kb
input:
14 4 0 3 1 3 3 1 3 0 4 -4 0 5 3 0 -4 -1 0 5 4 4 5 0 3 3 3 2 -4 2 5 1 1 2 4 1 4 0 4 -1 1 4 4 5 -2 4 1 4 -5 -2 5 3 5 3 -1 4 -5 4 1 2 4 5 4 0 5 -5 -4 -2 1 -2 -5 -2 5 3 4 3 5 -5 -1 1 2 4 1 5 -5 -3 3 -3 -3 -3 2 -3 -4 5 5 0 1 -3 -1 -3 -3 -4 -4 -3 0 6 1 -3 -3 -3 2 -2 -3 1 -4 -5 3 -3 6 -1 -4 -3 0 0 4 -4 -3 ...
output:
14.3245553203 0.0000000000 30.6896447944 18.7482240257 0.0000000000 0.0000000000 36.6326947621 33.4097258671 29.5562146354 23.3471558826 33.2530721411 31.4820814934 38.2804870998 0.0000000000
result:
wrong answer 5th numbers differ - expected: '30.2540122', found: '0.0000000', error = '1.0000000'