QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#680533#9434. Italian CuisinererebornzhouCompile Error//C++204.7kb2024-10-26 21:24:132024-10-26 21:24:13

Judging History

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

  • [2024-10-26 21:24:13]
  • 评测
  • [2024-10-26 21:24:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef pair<int,int> pii;

const int N=3e5+10;

const double pi = acos(-1.0); //圆周率,精确到15位小数
const double eps = 1e-8; //浮点数偏差值

int sgn(double x){  //判断与0的大小关系
    if(fabs(x)<eps) return 0;
    return x<0?-1:1;
}

int dcmp(double x,double y){  //判断两个浮点数的大小关系
    if(fabs(x-y)<eps) return 0;
    else return x<y?-1:1;
}

struct Point{
    double x,y;
    int p;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point(Point a,Point b){  //向量
        x=b.x-a.x, y=b.y-a.y;
    }

    Point operator + (Point B){ return Point(x+B.x,y+B.y); }
    Point operator - (Point B){ return Point(x-B.x,y-B.y); }
    Point operator * (double k){ return Point(x*k,y*k); } //向量与实数的乘法
    Point operator / (double k){ return Point(x/k,y/k); } //向量与实数的除法
    bool operator == (Point B){ return sgn(x-B.x)==0 && sgn(y-B.y==0); } //两个向量判等
};

// 以下向量相关

typedef Point Vector; //用点的数据结构来表示向量

double Cross(Vector A,Vector B){ return A.x*B.y - A.y*B.x; } //向量叉积,有正负

//以下线相关
struct Line{
    Point p1,p2;  //直线上两点
    Line(){}
    Line(Point p1,Point p2):p1(p1),p2(p2){}
    Line(Point p,double angle){  //根据一个点和倾斜角确定直线,0<=angle<pi
        p1=p;
        if(sgn(angle-pi/2)==0) { p2 = (p1 + Point(0,1));} //tan(pi/2)不存在
        else { p2 = (p1 + Point(1,tan(angle)));}
    }
    Line(double a,double b,double c){  //ax+by+c=0
        if(sgn(a)==0){
            p1 = Point(0,-c/b);
            p2 = Point(1,-c/b);
        }
        else if(sgn(b)==0){
            p1 = Point(-c/b,0);
            p2 = Point(-c/b,1);
        }
        else{
            p1 = Point(0,-c/b);
            p2 = Point(1,(-c-a)/b);
        }
    }
};

double Distance_point(Point A,Point B){ return hypot(A.x-B.x,A.y-B.y); }  //两点之间的距离

double Dis_point_line(Point p,Line v){   //点到直线的距离
    // cout<<p.x<<" "<<p.y<<" ["<<v.p1.x<<" "<<v.p1.y<<"] "<<" ["<<v.p2.x<<" "<<v.p2.y<<"] \n";
    // cout<<fabs((double)Cross(p-v.p1,v.p2-v.p1))/Distance_point(v.p1,v.p2)<<"\n";
    return fabs((double)Cross(p-v.p1,v.p2-v.p1))/Distance_point(v.p1,v.p2);
}

struct Circle{  //圆的定义
    Point c;  //圆心
    double r;  //半径
    Circle(){}
    Circle(Point c,double r):c(c),r(r){}
	Circle(double x,double y,double r):c(Point(x,y)),r(r){}
};

int Line_circle_relation(Line v,Circle C){
    double dst = Dis_point_line(C.c,v);
    if(dst < C.r) return 0;  //0:直线和圆香蕉
    if(dst - C.r==0) return 1; //1:直线和圆相切
    return 2;                       //2:直线在圆外
}

Point st[N];

void solve(){
    int n;
    cin>>n;
    int cx,cy,R;
    cin>>cx>>cy>>R;
    Circle C(Point(cx,cy),R);
    vector<Point> P;
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        P.push_back(Point(x,y));
    }
    for(int i=0;i<n;i++){
        P.push_back(P[i]);
    }

    auto check = [&](int i,int mid) -> bool {
        if(Cross(Vector(P[mid].x-P[i].x,P[mid].y-P[i].y),Vector(C.c.x-P[mid].x,C.c.y-P[mid].y))<0) return 0;
        if(Line_circle_relation(Line(P[i],P[mid]),C)==0) return 0;
        return 1;
    };

    int r=0;
    __int128 area=0;
    int maxn=0;
    n=P.size()/2;
    for(int l=0;l<n;l++){
        while(check(l,r+1)){
            area-=Cross(P[r],P[l]);
            area+=Cross(P[r],P[r+1]);
            area+=Cross(P[r+1],P[l]);
            r++;
        }
        // cout<<l<<" "<<r<<" "<<area<<"\n";
        maxn=max(abs(area),maxn);
        area-=Cross(P[r],P[l]);
        area-=Cross(P[l],P[l+1]);
        area+=Cross(P[r],P[l+1]);
    }
    cout<<maxn<<"\n";
}

signed main(){
    int T=1;
    cin>>T;
    // if(T!=3){
    //     for(int i=1;i<=T;i++){
    //         int n;
    //         cin>>n;
    //         int cx,cy,R;
    //         cin>>cx>>cy>>R;
    //         for(int i=1;i<=n;i++){
    //             int x,y;
    //             cin>>x>>y;
    //             p[i].x=x;
    //             p[i].y=y;
    //         }
    //         if(i==16){
    //             cout<<n<<"\n";
    //             cout<<cx<<" "<<cy<<" "<<R<<"\n";
    //             for(int i=1;i<=n;i++){
    //                 cout<<p[i].x<<" "<<p[i].y<<"\n";
    //             }
    //             return 0;
    //         }
    //     }
    // }
    // if(T==1){
    //     cout<<"0\n";
    //     return 0;
    // }
    while(T--){
        solve();
    }
}

Details

answer.code: In function ‘void solve()’:
answer.code:129:21: error: call of overloaded ‘abs(__int128&)’ is ambiguous
  129 |         maxn=max(abs(area),maxn);
      |                  ~~~^~~~~~
In file included from /usr/include/c++/13/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:42,
                 from answer.code:1:
/usr/include/stdlib.h:840:12: note: candidate: ‘int abs(int)’
  840 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/13/cstdlib:81:
/usr/include/c++/13/bits/std_abs.h:79:3: note: candidate: ‘constexpr long double std::abs(long double)’
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:75:3: note: candidate: ‘constexpr float std::abs(float)’
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:71:3: note: candidate: ‘constexpr double std::abs(double)’
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:61:3: note: candidate: ‘long long int std::abs(long long int)’
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/13/bits/std_abs.h:56:3: note: candidate: ‘long int std::abs(long int)’
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~