编程介的小学生 2017-05-22 00:44 采纳率: 20.5%
浏览 711
已采纳

A Foldy but a Goody

Problem Description
Suppose you have a strip of paper and are given instructions to fold the paper in one of two ways: an upper fold, where the right end of the paper is brought over to the top of the left end; and a lower fold, where the right end of the paper is brought below the left end. The diagram below illustrates both types of folds.

Now, after meticulously folding the strip several times, you are asked to unfold it by making a 90 degree angle at each crease. The example below shows the result of an upper fold, followed by a lower fold and then an unfolding.

If the left end of the folded strip is placed at the origin (0,0) and the first right angle is at (1,0), it is natural to ask the questions: Where will the second right angle be located? The third right angle? Where will the other end of the strip be located? Well, that’s for us to know and you to figure out.

Input
The input file will contain multiple test cases. The first line of the file will contain a single integer indicating the number of test cases. Each case will consist of a string of letters U and L indicating a series of upper and lower folds followed by an integer m. The length of the string will be between 1 and 30, inclusive. The value of m identifies a position on the paper. A value of m = 0 indicates the left end (at location (0, 0)). If there are n folds, then a value of m = 2n indicates the right end of the strip. Any value for m between these two extremes represents one of the right angles; m = 1 indicates the first right angle, and so on.

Output
For each test case, output a single line of the form (x,y) indicating the location of the right angle (or end point) specified by the problem. You should assume that if there are n folds in the test case, the length of the string is 2n so that the distance between creases is 1 unit long.

Sample Input
3
UL 4
UL 3
LLUL 13

Sample Output
(2,0)
(2,-1)
(1,-2)

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-05-23 17:46
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?