hdu 3174 logo (已知角度求点)

时间:2021-08-30 20:24:50

如此一道水题,比赛时居然卡了我3个小时。。天啊!!思维定式要人命啊!!

//Time:15MS	
//Memory:244K
#include <stdio.h>
#include <string.h>
#include <math.h>
const double PI=acos(-1.0);
double x,y,th;
void fd(int l)
{
x+=l*sin(2*PI*th/360);
y+=l*cos(2*PI*th/360);
}
void lt(int l)
{
th=th+l;
while(th>360)
th-=360;
while(th<0)
th+=360;
}
int main()
{
int cas,n,l;
char s[100];
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
x=0;y=0;th=0;
while(n--)
{
scanf("%s%d",s,&l);
switch(s[0])
{
case 'f':fd(l);break;
case 'b':fd(-l);break;
case 'l':lt(l);break;
case 'r':lt(-l);break;
}
}
double ans=x*x+y*y;
ans=pow(ans,0.5);
printf("%.0lf\n",ans);
}
return 0;
}