QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 1024 MB مجموع النقاط: 150

#9099. 多边形

الإحصائيات

考虑一个由水平和垂直边以及 $N$ 个顶点组成的多边形 $P$。多边形 $P$ 的边仅在端点处相交,且每个顶点恰好连接两条边的端点。当沿着多边形 $P$ 的边逆时针移动时,在每个顶点处会向左或向右转弯。我们将在顶点处向左转弯记为 $L$,向右转弯记为 $R$。这样,由 $L$ 和 $R$ 组成的字符串就表示了这个多边形。例如,图 1 中的多边形可以用字符串 $LLRLLRRLLRLLRLLRRLLR$ 表示。用字符串表示多边形时,字符串的起点始终设为多边形最左侧边的上方顶点。可以发现,该字符始终为 $L$。

图 1

图 2

由给定字符串表示的多边形必须满足以下条件:对于任意垂直线 $V$,$V$ 与多边形水平边内部(不包含端点的部分)的交点最多有 2 个。对于多边形 $P$,将包含 $P$ 的最小垂直和水平边矩形记为 $B(P)$,该矩形由与 $P$ 的最左、最右、最上、最下边重合的垂直和水平线确定(图 2)。

给定由字符 $L$ 和 $R$ 组成的长度为 $N$ 的字符串,绘制该字符串所表示的满足上述条件的多边形 $P$。此时,$P$ 的每条边长度必须为整数。请编写一个程序,使 $B(P)$ 的面积最小,并输出该最小值。你需要为管理员实现以下函数:

  • int polygon(string S):接收长度为 $N$ 的字符串 $S$ 作为参数。其中,字符串 $S$ 的每个字符均为 $L$ 或 $R$。该函数需找到 $S$ 所表示的所有多边形 $P$ 中使得 $B(P)$ 面积最小的那一个,并返回该面积。

实现细节

你需要提交一个名为 polygon.cpolygon.cpp 的文件。该文件中必须实现以下函数:

int polygon(string S);

该函数应按上述说明运行。当然,你可以创建其他函数供内部使用。提交的代码不得执行输入输出操作或访问其他文件。

数据范围

  • 输入字符串由字符 $L$ 或 $R$ 组成。
  • 输入字符串所表示的满足上述条件的多边形始终至少存在一个。
  • $4 \le N \le 800$。

子任务

  • 子任务 1 [20 分]:$N \le 10$。
  • 子任务 2 [36 分]:$N \le 40$。
  • 子任务 3 [21 分]:$N \le 100$。
  • 子任务 4 [73 分]:无额外限制。

样例

样例输入 1

8
LLLRRLLL

样例输出 1

6

样例输入 2

20
LLRLLRRLLRLLRLLRRLLR

样例输出 2

15

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.