QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187469#3858. Systematic salesmanzhylj#WA 2ms12224kbC++142.4kb2023-09-24 17:36:132023-09-24 17:36:14

Judging History

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

  • [2023-09-24 17:36:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12224kb
  • [2023-09-24 17:36:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int ll
#define mp make_pair
#define qr read()
#define nc getchar
#define in(x) x=read()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read()
{
    char ch=' ';
    int f=1,x=0;
    for(;!isdigit(ch);ch=nc())if(ch=='-')f*=-1;
    for(;isdigit(ch);ch=nc())x=x*10+ch-'0';
    return f*x;
}
bool blank(char ch){return ch==' '||ch=='\n'||ch=='\t';}
struct p
{
    int x,y;
}e[1000010];
vector<int>v;
bool cmp1(int e1,int e2){return e[e1].x<e[e2].x;}
bool cmp2(int e1,int e2){return e[e1].y>e[e2].y;}
int pos[1000010],id[1000010],siz[1000010];
void build(vector<int>v,int x,int f)
{
    if(v.size()==1)
    {
        id[x]=v[0];
        pos[v[0]]=x;
        siz[x]=1;
        return;
    }
    if(!f)sort(v.begin(),v.end(),cmp1);
    else sort(v.begin(),v.end(),cmp2);
    vector<int>v1,v2;
    int n=v.size();
    for(int i=0;i<n/2;i++)v1.push_back(v[i]);
    for(int i=n/2;i<n;i++)v2.push_back(v[i]);
    build(v1,x<<1,f^1);
    build(v2,x<<1|1,f^1);
    siz[x]=siz[x<<1]+siz[x<<1|1]+1;
}
vector<int>lis,lis2;
void dfs(int x)
{
    if(id[x])
    {
        v.push_back(id[x]);
        return;
    }
    if(siz[x<<1])dfs(x<<1);
    if(siz[x<<1|1])dfs(x<<1|1);
}
int pp,vis[1000010];
double calc(int x,int y)
{
    return sqrt((e[x].x-e[y].x)*(e[x].x-e[y].x)+(e[x].y-e[y].y)*(e[x].y-e[y].y));
}
bool cmp3(int a,int b)
{
    return calc(pp,a)<calc(pp,b);
}
signed main()
{
    int n=qr;
    for(int i=1;i<=n;i++)
    {
        in(e[i].x),in(e[i].y);
    }
    int f=0;
    for(int i=1;i<=n;i++)v.push_back(i);
    build(v,1,0);
    double mn=1e16;
    for(int i=1;i<=n;i++)
    {
        // cout<<"--------\n";
        int nw=i;
        double now=0;
        lis.clear();
        while(1)
        {
            // cout<<nw<<' ';
            lis.push_back(nw);
            int p=pos[nw];
            vis[p]=1;
            while((vis[p^1]||!siz[p^1])&&p)p>>=1,vis[p]=1;
            if(!p)break;
            v.clear();
            dfs(p^1);
            pp=nw;
            sort(v.begin(),v.end(),cmp3);
            now+=calc(nw,v[0]);
            nw=v[0];
        }
        for(int j=1;j<=4*n;j++)vis[j]=0;
        // cout<<'\n';
        if(now<mn)lis2=lis,mn=now;
    }
    printf("%.6f\n",mn);
    for(auto i:lis2)cout<<i<<' ';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 12224kb

input:

8
7 3
2 0
4 5
1 4
8 2
9 9
0 8
6 1

output:

26.383326
6 1 5 8 2 4 3 7 

result:

ok correct!

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 12052kb

input:

20
4 71
52 7
49 15
59 83
12 9
46 6
74 44
89 50
32 10
82 58
11 33
78 72
27 49
64 75
97 0
38 46
91 54
8 70
18 61
79 92

output:

390.552000
1 18 19 13 16 11 5 9 6 3 2 7 8 15 17 10 12 20 4 14 

result:

wrong answer The first line of your output is 390.552000, but the length of jury's solution is 374.883681