交了一份代码,可以AC,但无法通过题目的第一个样例,总体大概没什么问题,求大神佬帮助
代码:
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define N 100005
int n,s[N],tot,tot1;
double ans,l,h,r,xx,yy,th;
const double pi=3.1415926535;
struct node{
double x,y;
}a[N];
bool cmp(node a,node b){
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
double dis(int x,int y){
return sqrt((a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y));
}
double getk(int x,int y){
if(a[x].x==a[y].x)return inf;
return (a[x].y-a[y].y)/(a[x].x-a[y].x);
}
int main(){
cin>>n;
cin>>l>>h>>r;
for(int i=1;i<=n;i++){
cin>>xx>>yy>>th;
a[++tot1].x=(h/2-r)*cos(th)-(l/2-r)*sin(th)+xx;
a[tot1].y=(l/2-r)*cos(th)+(h/2-r)*sin(th)+yy;
a[++tot1].x=-(h/2-r)*cos(th)-(l/2-r)*sin(th)+xx;
a[tot1].y=(l/2-r)*cos(th)-(h/2-r)*sin(th)+yy;
a[++tot1].x=(h/2-r)*cos(th)+(l/2-r)*sin(th)+xx;
a[tot1].y=-(l/2-r)*cos(th)+(h/2-r)*sin(th)+yy;
a[++tot1].x=-(h/2-r)*cos(th)+(l/2-r)*sin(th)+xx;
a[tot1].y=-(l/2-r)*cos(th)-(h/2-r)*sin(th)+yy;
}
n=tot1;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
s[++tot]=i;
while(tot>=3&&getk(s[tot-2],s[tot])<getk(s[tot-2],s[tot-1]))
s[tot-1]=s[tot],tot--;
}
for(int i=1;i<=tot-1;i++)ans+=dis(s[i],s[i+1]);
tot=0;
for(int i=n;i>=1;i--){
s[++tot]=i;
while(tot>=3&&getk(s[tot-2],s[tot])<getk(s[tot-2],s[tot-1]))
s[tot-1]=s[tot],tot--;
}
for(int i=1;i<=tot-1;i++)ans+=dis(s[i],s[i+1]);
printf("%.2lf",ans+2*pi*r);
return 0;
}