Problem 1: Bovine Ballet [Brian Dean, 2013]

In an attempt to challenge the stereotypical perception of cows as awkward
creatures, Farmer John's prize cow Bessie has signed up for an introductory
ballet class. Her final performance is next week, and FJ wants to help her
by building a rectangular stage large enough so that she can perform her
entire dance without falling off the edges.

Bessie's dance will take place on a rectangular stage consisting of a grid
of 1 x 1 square cells. Bessie's four feet are described concisely as follows:

FR: Front right foot
FL: Front left foot
RR: Rear right foot
RL: Rear left foot

Her four feet start out in 4 adjacent cells forming a square as follows,
with Bessie facing north.

FL FR
RL RR

Bessie's dance follows a series of N instructions (1 <= N <= 1000), where
each instruction tells her to either move one foot by one cell or to pivot
90 degrees clockwise.

Instructions to move a foot consist of 3 characters, the first two
identifying the foot to move, and the final character specifying the
direction of movement (F = forward, B = back, R = right, L = left). For
example, "FRF" means Bessie should move her front right foot forward one
cell, and "RLR" means she should move her rear left foot right one cell.
Of course, the direction of movement is relative to the direction Bessie is
facing.

Instruction to pivot are also 3 characters, the first two specifying the
single foot that Bessie keeps planted, around which she rotates 90 degrees
clockwise. The last character is "P" (for pivot). For example, the
instruction "FRP" means Bessie should pivot 90 degrees clockwise about her
stationary front right foot. This means that if her feet are currently
situated as follows (with Bessie facing north)

.. .. ..
.. .. FR
.. FL ..
.. RL RR

then the after the instruction "FRP" her feet will be located as follows,
with Bessie now facing east:

RL FL ..
RR .. FR
.. .. ..
.. .. ..

Given the N instructions in Bessie's dance, please compute the minimum area
of a rectangular stage necessary contain her feet during the entire dance.

If Bessie clumsily ever moves one foot onto the same cell as another foot,
she will trip and fail to complete the dance; in this case, please output
-1. Note that this is the only case where Bessie will trip; she has become
quite flexible after all her practice, and can easily move her feet into
rather strange configurations (for example, with her back feet farther
forward than her front feet).

PROBLEM NAME: ballet

INPUT FORMAT:

* Line 1: The integer N.

* Lines 2..1+N: Each line contains one of the 3-character instructions
in Bessie's dance.

SAMPLE INPUT (file ballet.in):

3
FRF
FRP
RLB

INPUT DETAILS:

Bessie's dance consists of the instructions "front right foot forward",
"front right foot pivot", and "rear left foot back".

OUTPUT FORMAT:

* Line 1: The minimum area of a rectangular stage necessary to contain
Bessie's feet during the entire dance, or -1 if Bessie trips.

SAMPLE OUTPUT (file ballet.out):

16

OUTPUT DETAILS:

Bessie needs a 4 x 4 stage to complete her dance. Her feet move as follows:

.. .. .. ..
.. .. .. .. (facing north)
.. .. FL FR
.. .. RL RR

After FRF:

.. .. .. ..
.. .. .. FR (facing north)
.. .. FL ..
.. .. RL RR

After FRP:

.. RL FL ..
.. RR .. FR (facing east)
.. .. .. ..
.. .. .. ..

After RLB:

RL .. FL ..
.. RR .. FR (facing east)
.. .. .. ..
.. .. .. ..

Usaco_Contest_2013_Open_Bovine Problem 1. Bovine Ballet的更多相关文章

  1. 洛谷P3611 [USACO17JAN]Cow Dance Show奶牛舞蹈

    题目描述 After several months of rehearsal, the cows are just about ready to put on their annual dance p ...

  2. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

  3. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

  4. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  5. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  6. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  7. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  8. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  9. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

随机推荐

  1. LeetCode(225) Implement Stack using Queues

    题目 Implement the following operations of a stack using queues. push(x) – Push element x onto stack. ...

  2. Linux学习-开放源码的软件安装与升级简介

    什么是开放源码.编译程序与可执行文件 我们说过,在 Linux 系统上面,一个文件能不能被执行看的是有没有可执行的那个权限 (具有 x permission),不过,Linux 系统上真 正认识的可执 ...

  3. [转] sublime插件

    Sublime Text 系列 Sublime Text:学习资源篇 Sublime插件:增强篇 Sublime插件:Markdown篇 Sublime插件:C语言篇 Sublime插件:主题篇 Su ...

  4. ie9/8的iframe中jQuery报错

    此文章用于对工作中遇到的问题进行记录 jQuery 版本:1.9.1 按照一般的思路,jquery 1.x的是支持ie9及以下的,但是今天发现jquery报错了,代码错误位置在源码版本的第4888行 ...

  5. Oralce重做日志(Redo Log)

    1.简介 Oracle引入重做日志的目的:数据库的恢复. Oracle相关进程:重做日志写进程(LGWR). 重做日志性质:联机日志文件,oracle服务器运行时需要管理它们. 相关数据字典:v$lo ...

  6. 大数据学习——sparkRDD

    https://www.cnblogs.com/qingyunzong/p/8899715.html 练习1:map.filter //通过并行化生成rdd val rdd1 = sc.paralle ...

  7. Flask_WTForms源码流程(糙版)

    from flask import Flask, render_template, request, redirect # Form# _fields# validate# validata_name ...

  8. 《Effective Java》笔记 :(一)创建和销毁对象

    一 .考虑用静态工厂方法代替构造器 1. 静态工厂方法与设计模式中的工厂方法模式不同,注意不要混淆 例子: public static Boolean valueOf(boolean b){ retu ...

  9. 01 Java 代码是怎么运行的

    Java代码运行的方式 1:在开发工具中运行 2:双击 jar 文件运行 3:在命令行中运行 4:在网页中运行 上述运行方式都离不开 JRE,也就是 Java 运行时环境.实际上 JRE 仅包含运行 ...

  10. 使用 Rails Webpacker 安裝 Foundation 6

    動機 由於 foundation-rails 6.4.1 版本有個 Issue 目前還沒合併.加上 Rails 已經支援了 webpack 2.x.這篇文章純粹紀錄另外一種做法. 準備 開始使用之前需 ...