QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#112022#1182. LighthousesqinsanmaAC ✓1122ms14832kbC++142.4kb2023-06-09 15:01:512023-06-09 15:01:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-09 15:01:54]
  • 评测
  • 测评结果:AC
  • 用时:1122ms
  • 内存:14832kb
  • [2023-06-09 15:01:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;


double x[1000],y[1000];
double dist(int a,int b)
{
    return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}
bool a[1000][1000];
double dp[1000][1000][2];
int main()
{

    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        for(int i=1; i<=n; i++)
        {
            cin>>x[i]>>y[i];
            x[i+n]=x[i];
            y[i+n]=y[i];
        }
        for(int i=1; i<=2*n; i++)
        {
            for(int j=1; j<=2*n; j++)
            {
                a[i][j]=0;
                 dp[i][j][0]=dp[i][j][1]=0;
            }
        }
        int m;
        cin>>m;
        double ans=0;
        for(int i=1; i<=m; i++)
        {
            int xx,yy;
            cin>>xx>>yy;
            a[xx][yy]=1;
            a[yy][xx]=1;
            
            a[xx+n][yy]=1;
            a[yy][xx+n]=1;
            
            a[xx][yy+n]=1;
            a[yy+n][xx]=1;
            
            a[xx+n][yy+n]=1;
            a[yy+n][xx+n]=1;

            dp[xx][yy][0]=dp[yy][xx][0]=dp[xx+n][yy][0]=dp[yy][xx+n][0]=dp[xx][yy+n][0]=dp[yy+n][xx][0]=dp[yy+n][xx+n][0]=dp[xx+n][yy+n][0]=dist(xx,yy);
            dp[xx][yy][1]=dp[yy][xx][1]=dp[xx+n][yy][1]=dp[yy][xx+n][1]=dp[xx][yy+n][1]=dp[yy+n][xx][1]=dp[yy+n][xx+n][1]=dp[xx+n][yy+n][1]=dist(xx,yy);
            ans=max(ans,dist(xx,yy));
        }

        for(int len=n; len>=2; len--)
        {
            for(int l=1; l+len-1<=2*n; l++)
            {
                int r=l+len-1;
                for(int j=l+1; j<r; j++)
                {
                    if(a[l][j])
                    {
                        dp[l][j][1]=max(dp[l][j][1],dp[l][r][0]+dist(l,j));

                        dp[j][r][0]=max(dp[j][r][0],dp[l][r][0]+dist(l,j));
                        ans=max(ans,dp[l][j][1]);
                        ans=max(ans,dp[j][r][0]);
                    }

                    if(a[r][j])
                    {

                        dp[j][r][0]=max(dp[j][r][0],dp[l][r][1]+dist(r,j));
                        dp[l][j][1]=max(dp[l][j][1],dp[l][r][1]+dist(r,j));
                        ans=max(ans,dp[l][j][1]);
                        ans=max(ans,dp[j][r][0]);

                    }


                }
            }
        }

        cout<<fixed<<setprecision(9)<<ans<<endl;
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7724kb

input:

2
4
0 0
1 0
1 1
0 1
3
1 3
2 4
3 4
4
0 0
1 0
1 1
0 1
4
1 4
4 3
3 2
2 1

output:

2.414213562
3.000000000

result:

ok 2 numbers

Test #2:

score: 0
Accepted
time: 11ms
memory: 3668kb

input:

450
7
0 0
260338181 86092533
323066179 107441010
424697382 278447352
71444106 1000000000
-575302618 804979842
-258577414 97804732
20
2 3
2 5
1 3
7 4
2 1
5 3
6 2
7 5
4 2
3 6
1 7
5 6
4 6
4 5
3 4
7 2
6 1
1 5
7 6
4 1
5
0 0
713930457 800419774
94147955 958520832
-286069543 1000000000
-262432976 698118841...

output:

4765927085.197136879
3445280472.471964836
4807.744303066
3190.426973230
4345171440.261609077
6514.458110994
3773167316.242773056
2276985.135787843
1033.226499854
2035605.489658920
5547331390.472334862
0.000000000
2480.599962470
2348460308.029507637
7779.583217082
4517152358.373314857
1366112.7952040...

result:

ok 450 numbers

Test #3:

score: 0
Accepted
time: 1122ms
memory: 14832kb

input:

10
295
0 0
14682701 503060
25046284 1037424
36405162 1792084
39349419 2119133
68531516 5963501
88143287 8803232
105612921 11584151
110634846 12446595
115510397 13365788
123709362 15371938
138667321 19292100
143732922 20680197
152527267 23117317
161336760 25663342
175610584 29864225
179534317 3102751...

output:

138692526440.221313477
142741536635.014129639
210677906142.053436279
44669007984.586189270
143288343239.696929932
7617016839.570425034
49984226404.877372742
199989775093.763916016
206539582580.724273682
45567211025.837249756

result:

ok 10 numbers