QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768116#7846. Glacier TravelcaneToadCoadWA 0ms4000kbC++142.5kb2024-11-21 00:44:092024-11-21 00:44:09

Judging History

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

  • [2024-11-21 00:44:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4000kb
  • [2024-11-21 00:44:09]
  • 提交

answer

#include<vector>
#include<string>
#include<iostream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<float.h>
#include <iomanip> 
using namespace std;

#define LL long long int
#define pp pair<double,double>
#define x first
#define y second


double dist(pp a, pp b){
    return sqrt(pow(a.first-b.first,2)+pow(a.second-b.second,2));
}
pp uVec(pp a, pp b){
    double d = 1/dist(a,b);
    return {d*(b.x-a.x),d*(b.y-a.y)};
}

pp lerp(double p, double t, pp a, pp b){
    return {a.x+((p/t)*(b.x-a.x)),a.y+((p/t)*(b.y-a.y))};
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    double s, n;
    cin >> s >> n;
    vector<pp> points;
    for(int i = 0; i <n;i++){ 
        double a ,b ;
        cin >> a >> b;
        points.push_back({a,b});
    }
    double t = s;
    int i = 0;
    pp ao;
    pp bo;
    int aep;
    int beo;
    while(t > 0 && i < n-1){
        double d = dist(points[i],points[i+1]);
        if(t>d){
            t-=d;
            bo = points[i+1];
        }
        else{

            bo = lerp(t,d,points[i],points[i+1]);
            t = 0;
        }
        i++;
        beo = i;
    }
    double ans;
    
    if(beo == n-1 && bo == points[i-1]){
        ans = dist(points[0],points[i]);

    }
    else{
        ans = DBL_MAX;
        ao = points[0];
        aep = 1;
        while(beo < n){
            double da = dist(ao,points[aep]);
            double db = dist(bo,points[beo]);
            double lim = min(da,db);

            pp ae = lerp(lim, da, ao, points[aep]);
            pp be = lerp(lim, db, bo, points[beo]);
            ans = min(ans, dist(ae,be));
            ans = min(ans, dist(ao,bo));
            pp uVecA = uVec(ao,ae);
            pp uVecB = uVec(bo,be);

            double yint = 2*(ae.x-be.x)*(uVecA.x-uVecB.x);
            yint += 2*(ae.y-be.y)*(uVecA.y-uVecB.y);

            double grad = 2*pow(uVecA.x-uVecB.x,2);
            grad += 2*pow(uVecA.y-uVecB.y,2);

            if(grad != 0){
                double ta = (yint)/grad;
                if(0 <= ta && ta <= lim){
                    ans = min(ans,dist(lerp(ta,lim,ao,ae),lerp(ta,lim,bo,be)));
                }
            }
            ao = ae;
            bo = be;

            if(lim == da){
                aep++;
            }
            if(lim == db){
                beo++;
            }

        }
    }
    cout <<std::setprecision(10) <<  ans;



}

詳細信息

Test #1:

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

input:

5
4
20 0
10 0
10 10
0 10

output:

3.535533906

result:

ok found '3.53553', expected '3.53553', error '0.00000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4000kb

input:

3.16227766
9
-2 4
2 4
3 1
4 4
5 1
6 4
10 2
6 1
7 4

output:

0.9999999999

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

20
5
9 38
36 16
-5 36
-24 15
30 37

output:

2.29359576

result:

ok found '2.29360', expected '2.29360', error '0.00000'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3988kb

input:

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

output:

0.1320876332

result:

wrong answer 1st numbers differ - expected: '0.00000', found: '0.13209', error = '0.13209'