QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#315033#7846. Glacier Travellmf_upAC ✓4ms4516kbC++205.9kb2024-01-26 19:47:452024-01-26 19:47:46

Judging History

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

  • [2024-01-26 19:47:46]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:4516kb
  • [2024-01-26 19:47:45]
  • 提交

answer

#include<bits/stdc++.h>
#define cp const point &
#define cl const line &
#define cc const circle
#define LD long double
const LD eps = 1e-8;
const LD pi= acosl(-1);
int sgn(LD x)
{
    return x > eps ? 1 : (x < -eps ? -1 : 0);
}

LD sqr(LD x)
{ return x * x; }

struct point
{
    LD x, y;

    point operator+(cp a) const
    { return {x + a.x, y + a.y}; }

    point operator-(cp a) const
    { return {x - a.x, y - a.y}; }

    point operator*(LD t) const
    { return {x * t, y * t}; }

    point operator/(LD t) const
    { return {x / t, y / t}; }

    point rot(LD t) const
    { return {x * cos(t) - y * sin(t), x * sin(t) + y * cos(t)}; }

    point rot90() const
    { return {-y, x}; }

    double len2() const
    { return x * x + y * y; }

    double len() const
    { return sqrt(x * x + y * y); }

    point unit() const
    {
        double d = len();
        return {x / d, y / d};
    }
    friend bool operator<(cp a,cp b)
    {
        if(a.x!=b.x)
            return a.x<b.x;
        else return a.y<b.y;
    }
};

LD dot(cp a, cp b);

bool operator==(cp a, cp b)
{
    return sgn(dot(a - b, a - b));
}

LD dis(cp a, cp b)
{
    return sqrtl(sqr(a.x - b.x) +sqr(a.y - b.y));
}

LD dot(cp a, cp b)
{
    return a.x * b.x + a.y * b.y;
}

LD det(cp a, cp b)
{
    return a.x * b.y - b.x * a.y;
}

bool turn_left(cp a, cp b, cp c)
{
    return sgn(det(b - a, c - a)) >0;//大于等于是严格凸包,大于是非严格凸包可以有180°
}

struct line
{
    point s, t;
    line(point a,point b):s(a),t(b){}
};

bool same_dir(cl a, cl b)
{
    return sgn(det(b.t - b.s, a.t - a.s)) == 0 && sgn(dot(b.t - b.s, a.t - a.s)) > 0;
}

bool point_on_segment(cp a, cl l)//前一句是点在直线上
{
    return sgn(det(l.s - a, a - l.t)) == 0 && sgn(dot(l.s - a, a - l.t)) <= 0;
}
bool two_side(cp a,cp b,cl c)
{
    return sgn(det(a-c.s,c.t-c.s))*sgn(det(b-c.s,c.t-c.s))<0;
}
bool intersect_judge(cl a,cl b){
    if(point_on_segment(a.s,b)|| point_on_segment(a.t,b)|| point_on_segment(b.s,a)|| point_on_segment(b.t,a))return true;
    return two_side(a.s,a.t,b)&& two_side(b.s,b.t,a);
}
point line_intersect(cl a,cl b){
    double s1=det(a.t-a.s,b.s-a.s);
    double s2=det(a.t-a.s,b.t-a.s);
    return (b.s*s2-b.t*s1)/(s2-s1);
}
bool point_on_ray(cp a,cl b){
    return sgn(det(a-b.s,b.t-b.s))==0&&sgn(dot(a-b.s,b.t-b.s))>=0;
}
bool ray_intersect_judge(line a,line b)
{
    double s1,s2;
    s1=det(a.t-a.s,b.s-a.s);
    s2=det(a.t-a.s,b.t-a.s);
    if(sgn(s1)==0&&sgn(s2)==0)
        return sgn(dot(a.t-a.s,b.s-a.s))>=0||sgn(dot(b.t-b.s,a.s-b.s));
    if(!sgn(s1-s2)||sgn(s1)==sgn(s2-s1))return 0;
    std::swap(a,b);
    s1=det(a.t-a.s,b.s-a.s);
    s2=det(a.t-a.s,b.t-a.s);
    return sgn(s1)!=sgn(s2-s1);
}
LD point_to_line(cp a,cl b){
    return abs(det(b.t-b.s,a-b.s))/dis(b.s,b.t);
}
point project_to_line(cp a,cl b){
    return b.s+(b.t-b.s)*(dot(a-b.s,b.t-b.s)/(b.t-b.s).len2());
}
LD point_to_segment(cp a,cl b){
    if(sgn(dot(b.s-a,b.t-b.s))* sgn(dot(b.t-a,b.t-b.s))<=0)
        return abs(det(b.t-b.s,a-b.s))/dis(b.s,b.t);
    return std::min(dis(a,b.s),dis(a,b.t));
}
std::vector <point> convex_hull (std::vector <point> a) {
    int n = (int) a.size (), cnt = 0;
    if (n < 2) return a;
    std::sort(a.begin(), a.end()); // less<pair>
    std::vector <point> ret;
    for (int i = 0; i < n; ++i) {
        while (cnt > 1
               && !turn_left (ret[cnt - 1],  a[i],ret[cnt-2]))
            --cnt, ret.pop_back ();
        ++cnt, ret.push_back (a[i]); }
    int fixed = cnt;
    for (int i = n - 2; i >= 0; --i) {
        while (cnt > fixed
               && !turn_left (ret[cnt - 1],  a[i],ret[cnt-2]))
            --cnt, ret.pop_back ();
        ++cnt, ret.push_back (a[i]); }
    ret.pop_back (); return ret;
}
LD get_min(cp a1,cp a2,cp b1,cp b2,LD ti)
{
    point s=a2-a1,b=b2-b1;
    point t=s+b*ti;
    line ll={s,t};
    return point_to_segment({0,0},ll);
}
void solve()
{
    LD t;
    int n;
    std::cin>>t>>n;
    std::vector<point>pu(n);
    struct list{
        LD ti;
        int op;
        point a;
        point b;
        bool operator <(const list x)const{
            return ti<x.ti;
        }
    };
    std::vector<list>pp;
    LD rres=0;
    for(int i=0;i<n;i++)
    {
        LD x,y;
        std::cin>>x>>y;
        pu[i]={x-pu[0].x,y-pu[0].y};
    }
    for(int i=1;i<n;i++)
        rres+=dis(pu[i],pu[i-1]);
    pu[0]={0,0};
    LD res=0;
    point now={0,0};
    for(int i=0;i<n;i++)
    {
        if(i==n-1)
        {
            res+=dis(pu[i],now);
            pp.push_back({res,0,now,{0,0}});
        }
        else
        {
            res+=dis(pu[i],now);
            now=pu[i];
            pp.push_back({res,0,now,(pu[i+1]-pu[i]).unit()});
            if(res+t<rres)
            pp.push_back({res+t,1,now,(pu[i+1]-pu[i]).unit()});
        }
    }
    std::sort(pp.begin(),pp.end());
    int len=pp.size();
//    for(int i=0;i<len;i++)
//    {
//        auto [ti,op,a,b]=pp[i];
//        std::cout<<ti<<' '<<op<<' '<<a.x<<' '<<a.y<<' '<<b.x<<' '<<b.y<<std::endl;
//    }
    point a1,a2,b1,b2;
    LD res1=0,res2=0;
    LD ans=t;
    for(int i=0;i<len-1;i++)
    {
        auto [ti,op,a,b]=pp[i];
        if(op==0)
        {
            a1=a;b1=b;
            res1=ti;
            a2=a2+b2*(res1-res2);
            ans=std::min(ans, get_min(a1,a2,b1,b2,pp[i+1].ti-pp[i].ti));
        }
        else
        {
            a2=a,b2=b;
            res2=ti;
            a1=a1+b1*(res2-res1);
            ans=std::min(ans, get_min(a1,a2,b1,b2,pp[i+1].ti-pp[i].ti));
        }
    }
    std::cout<<ans<<std::endl;



}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),std::cout.tie(0);
    std::cout<<std::fixed<<std::setprecision(10);
    int T=1;
//    std::cin>>T;
    while(T--)
        solve();
}
/*
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4
20 0
10 0
10 10
0 10

output:

3.5355339059

result:

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

Test #2:

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

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: 3920kb

input:

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

output:

2.2935957604

result:

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

Test #4:

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

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.0000000000

result:

ok found '0.00000', expected '0.00000', error '-0.00000'

Test #5:

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

input:

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

output:

0.3442144373

result:

ok found '0.34421', expected '0.34421', error '0.00000'

Test #6:

score: 0
Accepted
time: 4ms
memory: 4516kb

input:

1000
4000
-720538 -681604
667325 347504
-911397 -962007
-264075 -858319
49605 149209
964851 361021
-397274 28661
-460607 -273701
104862 -136807
-803899 -693703
-974 -337735
323678 -209811
-745617 -358684
-984333 603546
722843 -444579
701511 -255784
-676477 -836480
998942 -227888
-502059 -438394
9641...

output:

0.0445047436

result:

ok found '0.04450', expected '0.04450', error '0.00000'

Test #7:

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

input:

1000
4000
703 909
500 496
-214 628
914 -44
-330 -238
-1424 -1426
347 1420
332 -1417
877 1678
-1390 819
-921 525
121 -923
-851 -859
512 -151
765 -109
416 -1529
-269 667
475 -234
-708 300
1917 -1935
-909 1342
1141 -696
-272 1295
1908 -1124
-898 -1225
1608 630
-1937 1246
-255 1021
-1005 -1650
-1595 -39...

output:

0.0381857100

result:

ok found '0.03819', expected '0.03819', error '0.00000'

Test #8:

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

input:

40
3
100 0
0 100
0 0

output:

15.3073372946

result:

ok found '15.30734', expected '15.30734', error '0.00000'

Test #9:

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

input:

48.2842712475
4
-10 -10
10 10
-10 10
10 -10

output:

0.0000000000

result:

ok found '0.00000', expected '0.00000', error '-0.00000'