事情是这样的.............
查看原帖
事情是这样的.............
524906
刘辰雨楼主2022/1/24 16:02

事情是这样的,本来我A掉了那道凸包蓝题模板,复制粘贴代码准备A这道水题。处理点的代码很简单,公式就是 (xcos(θ)ysin(θ),ycos(θ)+xsin(θ)) (x cos(\theta)-ysin(\theta) , ycos(\theta)+xsin(\theta) ),再加上中心坐标。处理代码就像这样——

scanf("%lf%lf%lf" , &xx, &yx , &th);
//        xx += eps;
//        yx += eps;
//        th += eps;
        double x=0 , y=0;
        x = (h/2-r)*cos(th)-(v/2-r)*sin(th)+xx;
        y = (v/2-r)*cos(th)+(h/2-r)*sin(th)+yx;
        cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
        x = -(h/2-r)*cos(th)-(v/2-r)*sin(th)+xx;
        y = (v/2-r)*cos(th)-(h/2-r)*sin(th)+yx;
		cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
        y = -(v/2-r)*cos(th)+(h/2-r)*sin(th)+yx;
        x = (h/2-r)*cos(th)+(v/2-r)*sin(th)+xx;
        cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
        x = -(h/2-r)*cos(th)+(v/2-r)*sin(th)+xx;
        y = -(v/2-r)*cos(th)-(h/2-r)*sin(th)+yx;
        cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;

就是分四次讨论,将四个角都求出来。但是——玄学的是,点的问题解决了,原来的AC模板出问题啦!!!

反复确认,单独输出,原来的模板代码粘贴过来结果就不一样了?!初始化也检查了,到底是什么问题啊qwq....

模板和此题代码附上,请大佬帮看一下吧qwq

Code:

模板

AC记录

#include <bits/stdc++.h>
using namespace std;
struct vec
{
    double x, y;
} a[100001];
int q[100001], top, n, vist[1000001];
double ans = 0;
inline double len(vec a, vec b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
inline double cj(vec a, vec b, vec p)
{
    return (b.x-a.x)*(p.y-a.y)-(b.y-a.y)*(p.x-a.x);
}
inline bool cmp(vec a, vec b)
{
    if (a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}
int main()
{
    scanf("%d" , &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lf%lf" , &a[i].x , &a[i].y);
    }
    sort(a + 1, a + n + 1, cmp);
    q[++top] = 1;
    q[++top] = 2;
    vist[1] = vist[2] = 1;
    for(int i = 3 ; i<= n ; i++)
    {
        if(vist[i] == 1)continue;
        if(top==1||cj(a[q[top-1]],a[q[top]],a[i]) > 0)
        {
            q[++top] = i;
            vist[i] = 1;
        }
        else
        {
            while(cj(a[q[top-1]],a[q[top]],a[i]) <= 0&&top>1)
            {
                vist[q[top]] = 0;
                top--;
            }
            q[++top] = i;
            vist[i] = 1;
        }
    }
    for(int i=2;i<=top;i++)ans+=len(a[q[i-1]],a[q[i]]);
    top = 0;
    q[++top]=n;
    for(int i=n-1;i>0;i--)
    {
        if(vist[i]==0)
        {
            q[++top] = i;
            break;
        }
    }
    for(int i = n-2 ; i>= 1 ; i--)
    {
        if(cj(a[q[top-1]],a[q[top]],a[i]) > 0||top==1)
        {
            q[++top] = i;
            vist[i] = 1;
        }
        else
        {
            while(cj(a[q[top-1]],a[q[top]],a[i]) <= 0 && top>1)
            {
                vist[q[top]] = 0;
                top--;
            }
            q[++top] = i;
            vist[i] = 1;
        }
        if(top <= 1)break;
    }
    for(int i=2;i<=top;i++)ans+=len(a[q[i-1]],a[q[i]]);
    printf("%.2lf",ans);
    return 0;
}

此题:

#include <bits/stdc++.h>
using namespace std;
struct vec
{
    double x, y;
} a[100001];
int q[100001]={}, top=0, n=0, vist[1000001]={};
double ans = 0.0,h=0,v=0,r=0,xx=0,yx=0,th=0;
inline double len(vec a, vec b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
inline double cj(vec a, vec b, vec p)
{
    return (b.x-a.x)*(p.y-a.y)-(b.y-a.y)*(p.x-a.x);
}
inline bool cmp(vec a, vec b)
{
    if (a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}

int main()
{
    scanf("%d" , &n);
    n *= 4;
    scanf("%lf%lf%lf" , &v , &h,&r);
    for (int i = 1; i <= n; )
    {
        scanf("%lf%lf%lf" , &xx, &yx , &th);
//        xx += eps;
//        yx += eps;
//        th += eps;
        double x=0 , y=0;
        x = (h/2-r)*cos(th)-(v/2-r)*sin(th)+xx;
        y = (v/2-r)*cos(th)+(h/2-r)*sin(th)+yx;
        cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
        x = -(h/2-r)*cos(th)-(v/2-r)*sin(th)+xx;
        y = (v/2-r)*cos(th)-(h/2-r)*sin(th)+yx;
		cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
        y = -(v/2-r)*cos(th)+(h/2-r)*sin(th)+yx;
        x = (h/2-r)*cos(th)+(v/2-r)*sin(th)+xx;
        cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
        x = -(h/2-r)*cos(th)+(v/2-r)*sin(th)+xx;
        y = -(v/2-r)*cos(th)-(h/2-r)*sin(th)+yx;
        cout<<x<<" "<<y<<endl;
        a[i++].x = x;
        a[i].y = y;
    }
    sort(a + 1, a + n + 1, cmp);
    sort(a + 1, a + n + 1, cmp);
    q[++top] = 1;
    q[++top] = 2;
    vist[1] = vist[2] = 1;
    for(int i = 3 ; i<= n ; i++)
    {
        if(vist[i] == 1)continue;
        if(top==1||cj(a[q[top-1]],a[q[top]],a[i]) > 0)
        {
            q[++top] = i;
            vist[i] = 1;
        }
        else
        {
            while(cj(a[q[top-1]],a[q[top]],a[i]) <= 0&&top>1)
            {
                vist[q[top]] = 0;
                top--;
            }
            q[++top] = i;
            vist[i] = 1;
        }
    }
    for(int i=2;i<=top;i++)ans+=len(a[q[i-1]],a[q[i]]);
    top = 0;
    q[++top]=n;
    for(int i=n-1;i>0;i--)
    {
        if(vist[i]==0)
        {
            q[++top] = i;
            break;
        }
    }
    for(int i = n-2 ; i>= 1 ; i--)
    {
        if(cj(a[q[top-1]],a[q[top]],a[i]) > 0||top==1)
        {
            q[++top] = i;
            vist[i] = 1;
        }
        else
        {
            while(cj(a[q[top-1]],a[q[top]],a[i]) <= 0 && top>1)
            {
                vist[q[top]] = 0;
                top--;
            }
            q[++top] = i;
            vist[i] = 1;
        }
        if(top <= 1)break;
    }
    for(int i=2;i<=top;i++)ans+=len(a[q[i-1]],a[q[i]]);
    cout<<3.141592653589793*2*r<<"  circle"<<endl;
    cout<<ans<<"  ans"<<endl;
    printf("%.2lf",ans+3.141592653589793*2*r);
    return 0;
}

救救孩子。。。。。。

2022/1/24 16:02
加载中...