QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386336#5809. Min PerimeterSimonLJK20 ✓14127ms35604kbC++141.7kb2024-04-11 15:36:252024-04-11 15:36:25

Judging History

你现在查看的是最新测评结果

  • [2024-04-11 15:36:25]
  • 评测
  • 测评结果:20
  • 用时:14127ms
  • 内存:35604kb
  • [2024-04-11 15:36:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N=1e6+99;
int n;
ld d;
struct node{
    ld x,y;
}p[N];
ld dist(node A,node B){
    return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
ld length(node A){
    return sqrt(A.x*A.x+A.y*A.y);
}
void rotate(node&A,ld alpha){
    ld len=length(A);
    if(len==0) return;
    ld c=A.x/len,s=A.y/len;
    ld cc=c*cos(alpha)+s*sin(alpha);
    ld ss=s*cos(alpha)-c*sin(alpha);
    A=(node){cc*len,ss*len};
}
bool cmp(node A,node B){
    return A.x<B.x||(A.x==B.x&&A.y<B.y);
}
bool cmpp(int A,int B){
    return p[A].y<p[B].y;
}
int q[N],cnt;
void merge(int l,int r){
    if(l==r) return;
    int mid=((l+r)>>1);
    merge(l,mid); merge(mid+1,r);
    cnt=0;
    for(int i=l;i<=r;i++)
        if(fabs(p[i].x-p[mid].x)<d/2)
            q[++cnt]=i;
    sort(q+1,q+cnt+1,cmpp);
    for(int i=1;i<=cnt;i++)
        for(int j=i+1;j<=cnt&&p[q[j]].y-p[q[i]].y<d/2;j++)
            for(int k=j+1;k<=cnt&&p[q[k]].y-p[q[i]].y<d/2;k++)
                d=min(d,dist(p[q[i]],p[q[j]]) + dist(p[q[j]],p[q[k]]) + dist(p[q[k]],p[q[i]]));
    return;
}
int main(){
//    freopen("triangle.in","r",stdin);
//    freopen("triangle.out","w",stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int T; cin>>T;
    int tt=0;
    while(T--){
        tt++;
        cin>>n;
        int alpha=abs(rand());
        for(int i=1;i<=n;i++){
            cin>>p[i].x>>p[i].y;
            rotate(p[i],alpha);
        }
        sort(p+1,p+n+1,cmp);
        d=dist(p[1],p[2])+dist(p[2],p[3])+dist(p[3],p[1]);
        merge(1,n);
        cout<<"Case #"<<tt<<": ";
        cout<<fixed<<setprecision(6)<<d<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 84ms
memory: 4584kb

input:

15
3
2 6
7 0
3 0
3
713 269
371 79
455 421
3
91983245 637281504
756917015 312173515
869576338 436726680
10000
14761642 78236002
9047458 47951098
5238002 27761162
476182 2523742
1428546 7571226
26190010 138805810
21904372 116092132
18094916 95902196
43332562 229660522
55237112 292754072
52380020 27761...

output:

Case #1: 17.893012
Case #2: 1042.844835
Case #3: 1711142102.791327
Case #4: 90912.296374
Case #5: 3.414214
Case #6: 26.153830
Case #7: 1701.012681
Case #8: 2865438.191994
Case #9: 2020088.337226
Case #10: 1792106.037292
Case #11: 2019352.542910
Case #12: 2530195.728018
Case #13: 930517.779631
Case #...

result:

ok correct! (15 test cases)

Subtask #2:

score: 15
Accepted

Test #2:

score: 15
Accepted
time: 14127ms
memory: 35604kb

input:

15
3
501691275 344354353
167768963 536043860
249445040 557426549
4
1000000000 0
0 0
1000000000 1000000000
0 1000000000
1000000
138925776 669369648
61257680 295150640
170762328 822763944
55483472 267329456
97736936 470914328
84041848 404928904
18463588 88960924
124429360 599523280
95066048 458045504
...

output:

Case #1: 799653579.133090
Case #2: 3414213562.373095
Case #3: 866.071591
Case #4: 62459.895370
Case #5: 59141.918359
Case #6: 898195.090968
Case #7: 1707085.769987
Case #8: 1686.226798
Case #9: 1686.603546
Case #10: 6806.665584
Case #11: 1907363.078325
Case #12: 1798829.537861
Case #13: 2000000.4819...

result:

ok correct! (15 test cases)

Extra Test:

score: 0
Extra Test Passed