【题目分析】
贪心。
【代码】
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const double pi=acos(-1.0);
int n,l;
double forward,backward;
int maxn=180;
double ans=0;
char s[101];
int dp[100001]; // mid 50000
int main()
{
dp[50000]=1;
scanf("%d",&n);
for (int i=1;i<=n;++i)
{
scanf("%s%d",&s,&l);
if (s[0]=='f') forward+=l;
if (s[0]=='b') backward+=l;
if (s[0]=='l') for (int i=0;i<=100000;++i) if (dp[i]) dp[i-l]=1;
if (s[0]=='r') for (int i=100000;i>=0;--i) if (dp[i]) dp[i+l]=1;
}
for (int i=0;i<=100000;++i)
if (dp[i]){
int tmp=((i-50000)%360+360)%360;
int cha=abs(180-tmp);
if (cha<maxn) maxn=cha;
}
ans=max(ans,forward);
forward+=cos((maxn*1.0)/180*pi)*backward;
backward=sin((maxn*1.0)/180*pi)*backward;
forward=sqrt(forward*forward+backward*backward);
ans=max(ans,forward);
printf("%.6f\n",ans);
}