QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618478#7005. Rikka with ConsistencyhhdhhAC ✓300ms5296kbC++231.6kb2024-10-06 22:39:132024-10-06 22:39:14

Judging History

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

  • [2024-10-06 22:39:14]
  • 评测
  • 测评结果:AC
  • 用时:300ms
  • 内存:5296kb
  • [2024-10-06 22:39:13]
  • 提交

answer

#include<bits/stdc++.h>
#define db double
using namespace std;
const int N=55;
const int eps=1e-10;
int T,n,h[N],m;
db f[N][N][N],D[N][N];
struct O{
    int a,b,c;db d;
};
queue<O>q;
void upd(int x,int y,int z,db v){
    if (f[x][y][z]-v>eps)
        f[x][y][z]=v,q.push((O){x,y,z,v});
}
void work(){
    scanf("%d",&n);m=0;
    for (int i=0;i<=n;i++)
        scanf("%d",&h[i]),m=max(m,h[i]);
    for (int i=0;i<=n;i++)
        for (int j=0;j<=n;j++)
            for (int k=0;k<=m;k++)
                f[i][j][k]=1e9;
    for (q.push((O){0,n,0,f[0][n][0]=0});!q.empty();){
        O u=q.front();q.pop();
        if (fabs(u.d-f[u.a][u.b][u.c])>eps) continue;
        if (u.a>0 && u.c==h[u.a])
            upd(u.a-1,u.b,u.c,u.d+(h[u.a-1]==h[u.a]));
        if (u.a<n && u.c==h[u.a+1])
            upd(u.a+1,u.b,u.c,u.d+(h[u.a+1]==h[u.a]));
        if (u.b>0 && u.c==h[u.b])
            upd(u.a,u.b-1,u.c,u.d+(h[u.b-1]==h[u.b]));
        if (u.b<n && u.c==h[u.b+1])
            upd(u.a,u.b+1,u.c,u.d+(h[u.b+1]==h[u.b]));
        if (u.a<n && u.b<n && u.c>min(h[u.a],h[u.a+1]) && u.c>min(h[u.b],h[u.b+1]))
            upd(u.a,u.b,u.c-1,u.d+D[h[u.a]][h[u.a+1]]+D[h[u.b]][h[u.b+1]]);
        if (u.a<n && u.b<n && u.c<max(h[u.a],h[u.a+1]) && u.c<max(h[u.b],h[u.b+1]))
            upd(u.a,u.b,u.c+1,u.d+D[h[u.a]][h[u.a+1]]+D[h[u.b]][h[u.b+1]]);
    }
    printf("%.10lf\n",f[n][0][0]);
}
int main(){
    for (int i=0;i<=50;i++)
        for (int j=0;j<=50;j++)
            if (i!=j) D[i][j]=sqrt(1.0*(1+(i-j)*(i-j))/((i-j)*(i-j)));
    for (scanf("%d",&T);T--;work());
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

12.1289902045
22.3136245686

result:

ok 2 cases

Test #2:

score: 0
Accepted
time: 51ms
memory: 5296kb

input:

500
34
0 12 2 25 18 11 17 7 24 20 19 18 34 26 14 15 11 16 3 19 6 21 34 33 12 6 29 10 27 22 5 7 7 25 0
40
0 18 15 11 15 10 9 26 34 13 35 12 27 36 33 3 7 28 6 24 12 30 38 39 14 14 12 13 24 35 28 35 11 22 19 39 8 6 18 3 0
43
0 25 1 23 21 5 16 36 22 3 31 34 9 3 41 17 11 39 22 0 16 39 15 10 8 33 24 21 20...

output:

1906.0227443439
1873.2359020590
2645.0638835510
541.3343735756
1235.7890705751
1951.6734665821
1213.9245379867
2017.5869647005
312.7644098498
3422.7892270311
138.6143738401
2149.9886075935
1046.3983990275
47.2354965428
2511.3020333589
60.5339378890
87.7918204661
2535.3037067975
13.6251184001
1041.33...

result:

ok 500 cases

Test #3:

score: 0
Accepted
time: 161ms
memory: 5068kb

input:

500
43
0 6 6 1 1 1 6 1 1 5 1 5 6 5 6 1 5 5 6 6 5 5 6 1 5 6 1 6 5 5 5 6 6 6 1 1 6 6 5 1 5 6 1 0
50
0 18 39 18 28 18 18 18 28 47 28 28 48 8 8 39 48 8 39 19 47 19 19 18 48 20 28 28 18 20 20 39 48 8 8 39 48 20 20 20 8 8 18 19 8 8 8 18 8 48 0
43
0 25 29 25 44 32 32 50 50 32 29 44 25 25 25 25 32 44 29 24 ...

output:

252.2065976424
2006.4352817212
1567.0389256057
247.4145601157
2355.1321913974
2039.2389722058
585.4789742390
1706.2900658340
2455.7783261244
1429.6683040297
386.2247435139
2328.3531873156
231.7998168538
1613.9361966965
1209.0836904200
933.4911595684
1443.0473731123
2567.8362512484
1821.0363941722
27...

result:

ok 500 cases

Test #4:

score: 0
Accepted
time: 300ms
memory: 5108kb

input:

500
42
0 27 22 28 20 31 17 33 14 34 13 35 11 42 8 44 4 49 2 50 1 23 3 47 5 46 7 43 9 41 10 38 12 36 16 32 18 30 19 29 23 23 0
44
0 23 23 27 20 32 18 36 15 38 11 44 8 45 6 47 4 48 3 23 1 50 5 46 7 43 9 42 12 41 13 40 14 37 16 35 17 33 19 31 21 29 22 28 0
48
0 48 3 46 5 44 7 41 9 39 11 37 13 35 15 32 ...

output:

19134.1832142733
24340.1014771679
4598.0135761173
35163.5943454349
19719.4946797100
24330.9798185223
17290.0968115849
31672.4505810898
30612.7890458490
21650.2868919423
26014.0448811728
10391.5615138846
25028.3336779188
36818.6491796744
29255.2609754668
24770.6063188668
17962.4126290369
21344.119291...

result:

ok 500 cases