关于样例没过AC
查看原帖
关于样例没过AC
119062
Lates楼主2020/8/1 16:53

RT 样例二输出 62.54 但是 AC 了。 记录

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double pi=acos(-1.0);
inline int read() {
    register int x=0,f=0,ch=getchar();
    while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
    while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
    return f?-x:x;
}
const int MAX=1e5+5;
struct V {
    double x,y;
} h[MAX],k,u,v;
V operator + (V a,V b) {
    return (V) {
        a.x+b.x,a.y+b.y
    };
}
V operator - (V a,V b) {
    return (V) {
        a.x-b.x,a.y-b.y
    };
}
double xmul(V a,V b) {
    return a.x*b.y-a.y*b.x;
}
double co,si;
V solve(double x,double y,double z) {
    co=cos(z),si=sin(z);
    return (V) {
        x*co-y*si,x*si+y*co
    };
}
int top,m,n,cnt;
int st[MAX];
double a,b,r,x,y,t,ans;
inline bool cmp(V a,V b) {
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
inline double dis(V a,V b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
signed main() {
//  freopen("in.in","r",stdin);
    m=read();
    scanf("%lf%lf%lf",&b,&a,&r);
    a=a/2.0-r;b=b/2.0-r; 
    for(register int i=1; i<=m; ++i) {
        scanf("%lf%lf%lf",&x,&y,&t);
        k=(V) {
            x,y
        };
        h[++n]=solve(a,b,t)+k;
        h[++n]=solve(a,-b,t)+k;
        h[++n]=solve(-a,b,t)+k;
        h[++n]=solve(-a,-b,t)+k;
    }
    sort(h+1,h+1+n,cmp);
    st[++top]=1,st[++top]=2;
    for(register int i=3; i<=n; ++i) {
        u=h[st[top]]-h[st[top-1]];
        v=h[i]-h[st[top]];
        while(top>1&&xmul(u,v)<0.0){
            --top;
            u=h[st[top]]-h[st[top-1]];
            v=h[i]-h[st[top]];
        }
        st[++top]=i;
    }   
    cnt=top;st[++top]=n,st[++top]=n-1;
    for(register int i=n-2;i;--i){
        u=h[st[top]]-h[st[top-1]];
        v=h[i]-h[st[top]];
        while(top>cnt&&xmul(u,v)<0.0){
            --top;
            u=h[st[top]]-h[st[top-1]];
            v=h[i]-h[st[top]];
        }
        st[++top]=i;
    }
    ans=2.0*pi*r;
    for(register int i=1;i<top;++i){
        ans+=dis(h[st[i]],h[st[i+1]]); 
    }
    printf("%.2lf\n",ans);
    return 0;
}
2020/8/1 16:53
加载中...