#include<iostream>//假设起点为00原点 #include<string> #include<math.h> using namespace std; double startx,starty;//当前开始坐标 double fx,fy;//方向 double distance;//距离 double pi=acos(-1); void move(double &startx,double &starty,double fx,double fy,int d)//求前进后的坐标 { startx+=d*fx; starty+=d*fy; } void round(double &fx,double &fy,double ra)//转向向左转的角度ra是弧度 { double s,c; fx/=sqrt(fx*fx+fy*fy); fy/=sqrt(fx*fx+fy*fy); s=fy*cos(ra)+fx*sin(ra); c=fx*cos(ra)-fy*sin(ra); fx=c; fy=s; } void com()//接受执行命令 { string str; cin>>str; int num; cin>>num; if(str=="fd") { move(startx,starty,fx,fy,num); } else if(str=="bk") { move(startx,starty,-fx,-fy,num); } else if(str=="lt") { round(fx,fy,num*pi/180);//不能写成num/180*pi } else { round(fx,fy,-num*pi/180); } } int main() { int k; cin>>k; while(k--) { fx=1;fy=0;startx=0;starty=0; int n;int i; cin>>n; for(i=0;i<n;i++) com(); printf("%0.0f/n",sqrt(startx*startx+starty*starty)); } return 0; } 三角函数的使用