zoukankan      html  css  js  c++  java
  • zjut1684AirCraft

    http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1684

    AirCraft 
    Time Limit:1000MS  Memory Limit:32768K
    Description:
    
    LCS has an aircraft, he can use some specific commands to make his aircraft to move. To simple the problem, you can assume the aircraft just move on the 2D-Plane.
    
    There are four commands :fd x, bk x, lt y, rt y.
    The command fd causes the aircraft to move forward by the specified number x of meters.
    The command bk causes the aircraft to move backward by the specified number x of meters.
    The command lt causes the aircraft to turn left by the specified number y of degrees.
    The command rt causes the aircraft to turn right by the specified number y of degrees.
    
    After executing many commands, LCS's aircraft maybe far away from it's start position. Your task is to calculate the straight-line distance from the LCS's aircraft present position to the position it started from.
    Input:
    
    The first line of input contains one integer specifying the number of test cases to follow. Each test case starts with a line containing one integer, the number of commands to follow. The commands follow, one on each line. Each test case will contain no more than 1000 commands.
    Output:
    
    For each test case, output a line containing a single integer indicating the distance rounded to the nearest meter.
    Sample Input:
    
    1
    5
    fd 100
    lt 120
    fd 100
    lt 120
    fd 100
    Sample Output:
    
    0
    
    #include<iostream>
    #include<string>
    #include<cmath>
    using namespace std;
    const double pi=3.141592653589;
    double x,y;
    double dir;
    void move(string s,double m)
    {
    	if(s=="fd")
    	{
              y+=sin(dir)*m;
    		  x+=cos(dir)*m;
    		  return ;
    	}
    	if(s=="bk")
    	{
              y-=sin(dir)*m;
    		  x-=cos(dir)*m;
    		  return;
    	}
    	if(s=="lt")
    	{
              dir+=m/360*pi*2;return;
    	}
    	if(s=="rt")
    	{
              dir-=m/360*pi*2;return;
    	}
    }
    double dis(double i,double j)
    {
         return pow(i*i+j*j,0.5);
    }
    int main()
    {
    	int cas,n;
    	double b;
    	string op;
    	cin>>cas;
    	while(cas--)
    	{
    		cin>>n;
    		x=0,y=0,dir=pi/2;
    		for(int i=0;i<n;i++)
    		{
                 cin>>op>>b;
    			 move(op,b);
    		}
            cout<<(int)(dis(x,y)+0.5)<<endl;
    
    	}
    
    }
    
  • 相关阅读:
    soj#547 bzoj5046 分糖果游戏
    soj#551 loj#2833 帐篷
    nb哒LCA
    soj#532 set p3175
    p4042 [AHOI2014/JSOI2014]骑士游戏
    p1501 [国家集训队]Tree II
    908G New Year and Original Order
    908D New Year and Arbitrary Arrangement
    EZOJ #258
    EZOJ #257
  • 原文地址:https://www.cnblogs.com/sook/p/2040223.html
Copyright © 2011-2022 走看看