QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625820#7003. Rikka with Minimum Spanning Treesucup-team5071#WA 0ms3968kbC++203.4kb2024-10-09 21:10:502024-10-09 21:10:51

Judging History

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

  • [2024-10-09 21:10:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3968kb
  • [2024-10-09 21:10:50]
  • 提交

answer

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

int n;
int h[55];
int difh[55];
double d[55];

double dp[55][55][2];

bool ava(double x1,double x2,double y1,double y2){
    double minx = min(x1,x2);
    double maxx = max(x1,x2);
    double miny = min(y1,y2);
    double maxy = max(y1,y2);
    return miny <= minx && maxx <= maxy;
}

bool gmin(double &x,double y){
    if (x > y) {x = y;return true;}
    return false;
}
double cal(double dh, int x){
    if (difh[x] == 0) return 0;
    return dh/difh[x]*d[x];
}

void solve(){

    cin >> n;
    for (int i = 0; i <= n; ++i){
        cin >> h[i];
    }
    if (n == 1){
        cout << 0 << "\n";
        return ;
    }
    for (int i = 0; i <= n; ++i){
        for (int j = 0; j <= n; ++j){
            dp[i][j][0] = 1e18;
            dp[i][j][1] = 1e18;
        }
    }
    dp[0][n][0] = 0;
    dp[0][n][1] = 0;
    for (int i = 0; i < n; ++i){
        int dif = abs(h[i+1]-h[i]);
        d[i] = sqrt(1+dif*dif);
        difh[i] = dif;
    }
    double dh;
    double nxt;


    for (int l = n; l >= 1; --l){
        for (int x = 0; x + l <= n; ++x){
            int y = x+l;
            if (ava(h[x],h[x+1],h[y-1],h[y])) {
                cout << "IN " << x << " " << y << " " << 0 << "\n";
                dh = abs(h[x+1]-h[x]);
                
                nxt = dp[x][y][0] + d[x] + cal(dh,y-1);
                gmin(dp[x+1][y][0],nxt);
                if(h[x+1] == h[y-1]) {
                    gmin(dp[x+1][y-1][0],nxt);
                    gmin(dp[x+1][y-1][1],nxt);
                }

                cout << nxt << " ";
                
                dh = abs(h[y-1] - h[x]);

                nxt = dp[x][y][0] + cal(dh,y-1) + cal(dh,x);
                gmin(dp[x][y-1][1],nxt);
                if (h[x+1] == h[y-1]){
                    gmin(dp[x+1][y-1][0],nxt);
                    gmin(dp[x+1][y-1][1],nxt);
                } 
                cout << nxt << "\n";
            }

           if (ava(h[y-1],h[y],h[x],h[x+1])){
                cout << "IN " << x << " " << y << " " << 1 << "\n";
                dh = abs(h[y]-h[y-1]);
                nxt = dp[x][y][1] + d[y] + cal(dh,x);;
                
                gmin(dp[x][y-1][1],nxt);
                if (h[x+1] == h[y-1]){
                    gmin(dp[x+1][y-1][0],nxt);
                    gmin(dp[x+1][y-1][1],nxt);
                }
                cout << nxt << " ";

                dh = abs(h[y]-h[x+1]);
                nxt = dp[x][y][1] + cal(dh,x) + cal(dh,y-1);
                gmin(dp[x+1][y][0],nxt);
                if (h[x+1] == h[y-1]){
                    gmin(dp[x+1][y-1][0],nxt);
                    gmin(dp[x+1][y-1][1],nxt);
                }
                cout << nxt << "\n";
            }
        }
    }
    double ans = 1e18;
    for (int i = 0; i <= n-1; ++i){
        ans = fmin(ans,dp[i][i+1][1]);
        ans = fmin(ans,dp[i][i+1][0]);
    }
    
    for (int i = 0; i <= n-1; ++i){
        cout << dp[i][i+1][0] << "\n";
    }
    for (int i = 0; i <= n-1; ++i){
        cout << dp[i][i+1][1] << "\n";
    }


    cout << ans*2 << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    int T;cin>>T;
    while(T--)solve();
}
/*
2
4
0 1 1 2 0
4
0 2 1 3 0

*/

/*
12.128990204491960
22.313624568639947
*/

/*
1
4
0 1 2 1 0
*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3968kb

input:

1
2 100000 123456789 987654321

output:

IN 0 1 0
1000000000000015616.000000000000000 1000000000000000000.000000000000000
IN 0 1 1
-nan 1000000000000000000.000000000000000
IN 1 2 0
-nan -nan
IN 1 2 1
-nan -nan
1000000000000000000.000000000000000
1000000000000000000.000000000000000
1000000000000000000.000000000000000
1000000000000000000.000...

result:

wrong answer 1st lines differ - expected: '575673759', found: 'IN 0 1 0'