注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

[nbut] 1248 Logo & [hdu] 3174 Logo  

2012-11-01 22:32:37|  分类: NBUT OJ |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
一道简单的几何题目。
fd x   向前x个单位
lt  x   顺时针旋转x度
bk x  向后x个单位
rt  x 逆时针旋转x度
  • 问题描述
  • Logo is a programming language built around a turtle. Commands in the language cause the turtle to move. The turtle has a pen attached to it. As the turtle moves, it draw lines on the page. The turtle can be programmed to draw interesting pictures.

    We are interested in making the turtle draw a picture, then return to the point that it started from. For example, we could give the turtle the following program:

    fd 100 lt 120 fd 100 lt 120 fd 100

    The command fd causes the turtle to move forward by the specified number of units. The command lt causes the turtle to turn left by the specified number of degrees. Thus the above commands cause the turtle to draw an equilateral triangle with sides 100 units long. Notice that after executing the commands, the turtle ends up in the same place as it started. The turtle understands two additional commands. The command bk causes the turtle to move backward by the specified number of units. The command rt causes the turtle to turn right by the specified number of degrees.

    After executing many commands, the turtle can get lost, far away from its starting position. Your task is to determine the straight-line distance from the turtle's position at the end of its journey back to the position that it started from.

  • 输入
  • 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.
  • 输出
  • For each test case, output a line containing a single integer, the distance rounded to the nearest unit.
  • 样例输入
  • fd 100 
    lt 120 
    fd 100 
    lt 120 
    fd 100
  • 样例输出
  • 0



#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;

const double PI = acos(-1.0);
double x,y,t;

void fd(int d)
{
x += d * sin(2 * PI * t / 360);
y += d * cos(2 * PI * t / 360);
}

void lt(int d)
{
t += d;
while(t > 360)
t -= 360;
while(t < 0)
t += 360;
}
int main()
{
int N; cin>>N;
while(N--)
{
x = 0,y = 0,t = 0;
int n; cin>>n;
while(n--)
{
char str[10];
int d;
scanf("%s%d",str,&d);
if(str[0] == 'f') fd(d);
if(str[0] == 'l') lt(d);
if(str[0] == 'b') fd(-d);
if(str[0] == 'r') lt(-d);
}
printf("%.0lf\n",sqrt(x * x + y * y));
}
}

/*
样例输入
1
5
fd 100
lt 120
fd 100
lt 120
fd 100
样例输出
0*/



  评论这张
 
阅读(172)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018