HBC24703重返小学,数学,快速幂,数据结构,栈,递归,分治,模拟[USACO 2011 Feb B]Cow Cotillion题解

一天到晚红烧的鱼 算法基础篇 70 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
The cow cotillion, a fancy dance every spring, requires the cows and bulls (shown as " >< >< < > >< < >

The cow cotillion, a fancy dance every spring, requires the cows (shown as ">") and bulls (shown as "<") to bow to each other during a dance. Schematically, one properly bowing pair of cattle is shown like this: "><". Sometimes another pair of cattle will sashay between a pair of bowing cows: "> >< <". In fact, sometimes a larger number of cows will mix it up on the dance floor: "> >< < ><" (this includes a second set of bowing cows on the right). Complex arrangements can be perfectly legal dance formations: > > > >< < >< < >< >< >< < | | | -- | -- | -- -- -- | | | ------ | | | ------------- | -------------------------- Farmer John notices that a stray heifer sometimes sneaks into a group and unbalances it: "> >< < <><". This is strictly forbidden; FJ wants to punish the interlopers. FJ has copied down records of as many as 500 cows participating in dance lines and wonders if the dance line is properly balanced (i.e., all of the cattle can be paired off in at least one way as properly bowing pair by pair). He copied only the direction each cow was bowing without any extra spaces to help determine which cow was bowing to which bull, strings like this rendition of the illegal example from the previous paragraph: ">><<<><". He wants you to write a program to tell him if the dance line is legal. FJ has N (1 <= N <= 1,000) pattern recordings P_i comprising just the characters '>' and '<' with varying length K_i (1 <= K_i <= 200).  Print "legal" for those patterns that include proper pairs of bowing cows and "illegal" for those that don't.

HBC24703重返小学,数学,快速幂,数据结构,栈,递归,分治,模拟[USACO 2011 Feb B]Cow Cotillion题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
全网最全C++题库,助您挑战自我,突破极限,成为编程领域的佼佼者!

标签: HBC24703重返小学 数学 快速幂 数据结构 递归 分治 模拟[USACO 2011 Feb B]Cow Cotillion题解