这道题没啥说,就是一个找最大值,但是我们需要找的是在整个过程中出现最大的距离,所以这道题我们需要对最大值一直转移,然后就写出来
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
const int N=100010;
using namespace std;
double dis[N];
signed main()
{
int T;
cin>>T;
char s;
int x=0;
int y=0;
double res;
for(int i=0;i<T;i++)
{
cin>>s;
if(s=='U')
{
y++;
}
else if(s=='D')
{
y--;
}
else if(s=='R')
{
x++;
}
else
{
x--;
}
dis[i]=sqrt(x*x+y*y);
}
res=dis[0];
for(int i=1;i<T;i++)
{
res=max(res,dis[i]);
}
printf("%.12lf",res);
return 0;
}