当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

BZOJ4512:[Usaco2016 Jan] Build Gates

题目描述
Farmer John decides to build a new fence around parts of his farm, but he keeps getting distracted a
nd ends up building the fence into a much stranger shape than he intended!Specifically, FJ starts at
 position (0,0)and takes N steps, each moving one unit of distance north, south, east, or west. Each
 step he takes, he lays a unit of fence behind him. For example, if his first step is to the north, 
he adds a segment of fence from (0,0) to (0,1). FJ might re-visit points multiple times and he may e
ven lay the same segment of fence multiple times. His fence might even cross over itself if his path
 cuts through a run of fencing he has already built.Needless to say, FJ is rather dismayed at the re
sult after he completes the fence. In particular, he notices that it may be the case that he has now
 partitioned off some areas of the farm from others, so that one can no longer walk from one region 
to another without crossing a fence. FJ would like to add gates to his fences to fix this problem. A
 gate can be added to any unit-length segment of fence he has built, allowing passage between the tw
o sides of this segment.Please determine the minimum number of gates FJ needs to build so that every
 region of the farm is once again reachable from every other region.
给定一个包含N,S,E,W的移动序列。FJ初始在(0,0),依次按照移动序列移动,并在移动过程中建设篱笆。如FJ在(0
,0)点,要向N移动,则FJ移动到(0,1),并在(0,0)和(0,1)之间建一段篱笆。注意到这样建设出的篱笆可能自交,
把平面划分成若干区域。现在要拆除若干段篱笆,使平面连通。输出最少拆除的篱笆段数。1 ≤ N ≤ 1000

输入解释
The first line of input contains N(1≤N≤1000). The next line contains a string of length N
describing FJ's path. Each character is either N (north), E (east), S (south), or W (west).

输出解释
Write out a single integer giving the minimum number of gates FJ needs to build to restore complete connectivity to all regions of his farm. Note that the answer could be zero if the farm is connected to begin with.

输入样例
14
NNNESWWWSSEEEE
输出样例
2
提示

BZPRO Powered by Remmina.
Github Repository
来自acmore.cc的附加信息
bzoj_id 4512
import_source_sha256 58f1b08aa065cbf267c6b491a3bd5c56a08439a0891750e495bb8e96b3fb60f6
bzoj_checker_pending False

该题目包含在题集 大视野(八中)OJ 中

题目来源 BZOJ 4512

源链接: LOCAL-BZOJ4512

共提交 0 次

通过率 --%
时间上限 内存上限
10000 MS 128 MB