QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639185#9434. Italian CuisineDixiky_215WA 30ms13360kbC++204.6kb2024-10-13 18:13:122024-10-13 18:13:14

Judging History

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

  • [2024-10-13 18:13:14]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:13360kb
  • [2024-10-13 18:13:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const double eps=1e-14;
const int MAXN=5e5+7;                                                         
struct Point{                                                                        
    double x,y;                                                                      
    Point(double x=0,double y=0):x(x),y(y){}
};
typedef Point Vector;
Point a[MAXN],be;
vector<Point> c;
int t;
int n;
double be_x,be_y,r;
ll sum[MAXN];

Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double B){return Vector(A.x*B,A.y*B);}
Vector operator / (Vector A,double B){return Vector(A.x/B,A.y/B);}

int dcmp(double x){if(fabs(x)<eps)return 0;return (x>0)?1:-1;}
bool operator == (const Vector A,const Vector B){
    return dcmp(A.x-B.x)==0 && dcmp(A.y-B.y)==0;
}
double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}  
double Length(Vector A){return sqrt(Dot(A,A));}                        
double Cross(Vector A,Vector B){return A.x*B.y-B.x*A.y;}              

double DistanceToSegment(Point P,Point A,Point B){
    if(A==B)return Length(P-A);
    Vector v1=B-A,v2=P-A,v3=P-B;
    if(dcmp(Dot(v1,v2))<0)return Length(v2);           
    else if(dcmp(Dot(v1,v3))>0)return Length(v3);      
    else return fabs(Cross(v1,v2))/Length(v1);                   
}
bool check2(Point P,Point A,Point B){
    if(A==B)return Length(P-A);
    Vector v1=B-A,v2=P-A,v3=P-B;
    if(dcmp(Dot(v1,v2))<0)
    {
        if(Length(v2)>r-eps) return 1;
        return 0; 
    }          
    else if(dcmp(Dot(v1,v3))>0)
    {
        if(Length(v3)>r-eps) return 1;
        return 0; 
    }    
    else
    {
        if(fabs(Cross(v1,v2))>r*Length(v1)-eps) return 1;
        return 0;
    }
}
double ComputePolygonArea(vector<Point> &points)
{
    int point_num = points.size();
    if(point_num < 3)return 0.0;
    double s = points[0].y * (points[point_num-1].x - points[1].x);
    for(int i = 1; i < point_num; ++i)
        s += points[i].y * (points[i-1].x - points[(i+1)%point_num].x);
    return fabs(s/2.0);
}

double Distance(Point p,Point a,Point b)
{
    Vector v1=b-a,v2=p-a;
    return fabs(Cross(v1,v2));
}
// bool check2(Point a,Point b)
// {
//     Point kkk={be_x,be_y};
//     if(Distance(kkk,a,b)<(r*abs(Length(b-a)))) return 0;
//     return 1;
// }
bool check1(Point a,Point b,Point c)
{
    __int128 res1=Cross(a,b),res2=Cross(a,c);
    if(res1*res2<0) return 0;
    return 1;
}
ll work(int l,int r)
{
    ll res=sum[r]-sum[l];
    c.clear();
    c.push_back(a[1]);
    c.push_back(a[l]);
    c.push_back(a[r]);
    res-=(ll) (ComputePolygonArea(c)*2.0);
    return res;
}
int main()
{
    cin.tie(nullptr) ->sync_with_stdio(false);

    cin>>t;
    while(t--)
    {
        cin>>n;
        cin>>be_x>>be_y>>r;
        be={be_x,be_y};
        for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
        for(int i=n+1;i<=2*n;i++) a[i]=a[i-n];
        
        sum[0]=sum[1]=sum[2]=0;
        for(int i=3;i<=n;i++)
        {
            c.clear();
            c.push_back(a[1]);
            c.push_back(a[i-1]);
            c.push_back(a[i]);
            sum[i]=sum[i-1]+(ll) (ComputePolygonArea(c)*2.0);
        }
        ll ans=0LL;
    
        for(int i=1;i<=n;i++)
        {
            int l=i,r=i+n-1,mid,loc=-1;
            Point k1=be-a[i];
            Point k2=a[i+1]-a[i];
            while(l<=r)
            {
                mid=(l+r)>>1;
                Point k3=a[mid]-a[i];
                if(check1(k1,k2,k3))
                {
                    if(check2(be,a[i],a[mid])) loc=mid,l=mid+1;
                    else r=mid-1;
                }
                else r=mid-1;
            }
            if(loc!=-1)
            {
                int lk=i%n,rk=loc%n;
                if(lk==0) lk=n;
                if(rk==0) rk=n;
                if(rk<lk)
                {
                    ll sum1=work(lk,n);
                    ll sum2=work(1,rk);
                    c.clear();
                    c.push_back(a[lk]);c.push_back(a[n]);
                    c.push_back(a[1]);c.push_back(a[rk]);
                    ll sumk=(ll) (ComputePolygonArea(c)*2.0);
                    
                    ans=max(ans,sum1+sum2+sumk);
                }
                else
                {
                    ans=max(ans,work(lk,rk));
                }
            }
        }
        cout<<ans<<'\n';
    }
    
    return 0;
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

5
24
0

result:

ok 3 number(s): "5 24 0"

Test #2:

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

input:

1
6
0 0 499999993
197878055 -535013568
696616963 -535013568
696616963 40162440
696616963 499999993
-499999993 499999993
-499999993 -535013568

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 30ms
memory: 12536kb

input:

6666
19
-142 -128 26
-172 -74
-188 -86
-199 -157
-200 -172
-199 -186
-195 -200
-175 -197
-161 -188
-144 -177
-127 -162
-107 -144
-90 -126
-87 -116
-86 -104
-89 -97
-108 -86
-125 -80
-142 -74
-162 -72
16
-161 -161 17
-165 -190
-157 -196
-154 -197
-144 -200
-132 -200
-128 -191
-120 -172
-123 -163
-138...

output:

5093
2862
2539
668
3535
7421
4883
5711
5624
1034
2479
3920
4372
2044
4996
5070
2251
4382
4175
1489
1154
3231
4038
1631
5086
14444
1692
6066
687
1512
4849
5456
2757
8341
8557
8235
1013
5203
10853
6042
6300
4480
2303
2728
1739
2187
3385
4266
6322
909
4334
1518
948
5036
1449
2376
3180
4810
1443
1786
47...

result:

wrong answer 2nd numbers differ - expected: '3086', found: '2862'