QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#387619#8505. Almost AlignedinstallbCompile Error//C++143.8kb2024-04-12 17:45:002024-04-12 17:45:00

Judging History

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

  • [2024-04-12 17:45:00]
  • 评测
  • [2024-04-12 17:45:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
const db eps = 1e-14;
const db pi = acos(-1.0);
const db MX = 8e9;

const int N = 2000005;

int sgn(db x){
    if(x > -eps && x < eps) return 0;
    if(x > 0) return 1;
    return -1;
}

struct point{
    db x,y;
    point (db _x = 0.0,db _y = 0.0) : x(_x), y(_y) {}
    bool operator < (const point &p) const{
        if(sgn(x - p.x) == 0) return sgn(y - p.y) < 0;
        return x < p.x;
    }
};
point operator - (const point &p1,const point &p2){
    return point(p1.x - p2.x,p1.y - p2.y);
}
point operator + (const point &p1,const point &p2){
    return point(p1.x + p2.x,p1.y + p2.y);
}
point operator * (db x,const point &p){
    return point(x * p.x,x * p.y);
}

db dot(point p1,point p2){
    return p1.x * p2.x + p1.y * p2.y;
}

db det(point p1,point p2){
    return p1.x * p2.y - p2.x * p1.y;
}

int n;
db x[N],y[N],vx[N],vy[N];
point p[N],q[N]; db qt[N]; int m;

vector <pair <db,point> > H[2][2];
vector <db> ti;
void calct(int id,int xy){
    vector <point> G;
    for(int i = 1;i <= n;i ++){
        if(!xy) p[i] = point(vx[i],x[i]);
        else p[i] = point(vy[i],y[i]);
    }
    sort(p + 1,p + 1 + n);
    if(!id){
        m = 0; q[++ m] = p[1];
        for(int i = 2;i <= n;i ++){
            if(m == 1 && (p[i].x == q[m].x && p[i].y > q[m].y)) m --;
            while(m > 1 && sgn(det(q[m] - q[m - 1],p[i] - q[m - 1])) >= 0) m --;
            q[++ m] = p[i];
        }
    }
    else{
        m = 0; q[++ m] = p[n];
        for(int i = n - 1;i >= 1;i --){
            if(m == 1 && (p[i].x == q[m].x && p[i].y < q[m].y)) m --;
            while(m > 1 && sgn(det(q[m] - q[m - 1],p[i] - q[m - 1])) >= 0) m --;
            q[++ m] = p[i];
        }
    }
    qt[1] = -MX;
    for(int i = 2;i <= m;i ++){
        qt[i] = (q[i - 1].y - q[i].y) / (q[i].x - q[i - 1].x);
    }
    for(int i = 1;i <= m;i ++){
        // cout << qt[i] << ';' << q[i].x << ',' << q[i].y << " \n"[i == m];
        if(qt[i] >= -MX - eps && qt[i] <= MX + eps){
            ti.push_back(qt[i]);
            H[id][xy].push_back({qt[i],q[i]});
        }
    }
}

void solve(){
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++){
        scanf("%lf %lf %lf %lf",&x[i],&y[i],&vx[i],&vy[i]);
    }
    calct(0,0);
    calct(1,0);
    calct(0,1);
    calct(1,1);

    ti.push_back(MX);
    sort(ti.begin(),ti.end());
    ti.erase(unique(ti.begin(),ti.end()),ti.end());
    db ans = 1e99;
    for(int i = 0;i + 1 < ti.size();i ++){
        db l = max(0.0,ti[i]),r = max(0.0,ti[i + 1]);
        auto [xut,xu] = *(-- upper_bound(H[0][0].begin(),H[0][0].end(),make_pair(l + eps,point(MX + 1,0))));
        auto [xdt,xd] = *(-- upper_bound(H[1][0].begin(),H[1][0].end(),make_pair(l + eps,point(MX + 1,0))));
        auto [yut,yu] = *(-- upper_bound(H[0][1].begin(),H[0][1].end(),make_pair(l + eps,point(MX + 1,0))));
        auto [ydt,yd] = *(-- upper_bound(H[1][1].begin(),H[1][1].end(),make_pair(l + eps,point(MX + 1,0))));
        // cout << l << ' ' << r << " : ";
        for(int ti = 1;ti <= 160;ti ++){
            db midl = (l + l + r) / 3.0;
            db midr = (l + r + r) / 3.0;
            db calcl = ((xu.x * midl + xu.y) - (xd.x * midl + xd.y)) * ((yu.x * midl + yu.y) - (yd.x * midl + yd.y));
            db calcr = ((xu.x * midr + xu.y) - (xd.x * midr + xd.y)) * ((yu.x * midr + yu.y) - (yd.x * midr + yd.y));
            ans = min(ans,min(calcl,calcr));
            if(calcl < calcr) r = midr;
            else l = midl;
        }
        // cout << l << ' ' << xu.x << ',' << xu.y << ' ' << xd.x << ',' << xd.y << ' ' << yu.x << ',' << yu.y << ' ' << yd.x << ',' << yd.y << ' ' << ans << '\n';
    }
    cout << fixed << setprecision(15) << ans << '\n';
}

int main(){
    solve();
    return 0;
}

详细

answer.code: In function ‘void solve()’:
answer.code:88:18: warning: format ‘%lf’ expects argument of type ‘double*’, but argument 2 has type ‘db*’ {aka ‘long double*’} [-Wformat=]
   88 |         scanf("%lf %lf %lf %lf",&x[i],&y[i],&vx[i],&vy[i]);
      |                ~~^              ~~~~~
      |                  |              |
      |                  double*        db* {aka long double*}
      |                %Lf
answer.code:88:22: warning: format ‘%lf’ expects argument of type ‘double*’, but argument 3 has type ‘db*’ {aka ‘long double*’} [-Wformat=]
   88 |         scanf("%lf %lf %lf %lf",&x[i],&y[i],&vx[i],&vy[i]);
      |                    ~~^                ~~~~~
      |                      |                |
      |                      double*          db* {aka long double*}
      |                    %Lf
answer.code:88:26: warning: format ‘%lf’ expects argument of type ‘double*’, but argument 4 has type ‘db*’ {aka ‘long double*’} [-Wformat=]
   88 |         scanf("%lf %lf %lf %lf",&x[i],&y[i],&vx[i],&vy[i]);
      |                        ~~^                  ~~~~~~
      |                          |                  |
      |                          double*            db* {aka long double*}
      |                        %Lf
answer.code:88:30: warning: format ‘%lf’ expects argument of type ‘double*’, but argument 5 has type ‘db*’ {aka ‘long double*’} [-Wformat=]
   88 |         scanf("%lf %lf %lf %lf",&x[i],&y[i],&vx[i],&vy[i]);
      |                            ~~^                     ~~~~~~
      |                              |                     |
      |                              double*               db* {aka long double*}
      |                            %Lf
answer.code:100:19: error: no matching function for call to ‘max(double, __gnu_cxx::__alloc_traits<std::allocator<long double>, long double>::value_type&)’
  100 |         db l = max(0.0,ti[i]),r = max(0.0,ti[i + 1]);
      |                ~~~^~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:100:19: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long double>, long double>::value_type’ {aka ‘long double’})
  100 |         db l = max(0.0,ti[i]),r = max(0.0,ti[i + 1]);
      |                ~~~^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:100:19: note:   deduced conflicting types for parameter ‘const _Tp’ (‘double’ and ‘__gnu_cxx::__alloc_traits<std::allocator<long double>, long double>::value_type’ {aka ‘long double’})
  100 |         db l = max(0.0,ti[i]),r = max(0.0,ti[i + 1]);
      |                ~~~^~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:100:19: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
  100 |         db l = max(0.0,ti[i]),r = max(0.0,ti[i + 1]);
      |                ~~~^~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
answer.code:100:19: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘double’
  100 |         db l = max(0.0,ti[i]),r = max(0.0,ti[i + 1]);
      |                ~~~^~~~~~~~~~~
answer.code:101:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  101 |         auto [xut,xu] = *(-- upper_bound(H[0][0].begin(),H[0][0].end(),make_pair(l + eps,point(MX + 1,0))));
      |              ^
answer.code:102:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  102 |         auto [xdt,xd] = *(-- upper_bound(H[1][0].begin(),H[1][0].end(),make_pair(l + eps,point(MX + 1,0))));
      |              ^
answer.code:103:14: warnin...