QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22310. 吃飯的乳牛(銅組)

Statistics

乳牛對飯友十分固執。分成編號 $1$ 和 $2$ 兩組,堅持依序一起吃飯,$1$ 組在隊首,$2$ 組在隊尾。到牛棚排隊進入餵食區時就有問題了。

乳牛 $i$ 帶小卡片,刻有 $D_{i}$($1 \le D_{i} \le 2$)表示飯組。全部 $N$ 頭($1 \le N \le 30{,}000$)已排隊,卻明顯未按卡片分組。

FJ 沿隊伍劃掉舊號碼寫上新號碼來改分組,工作並不難。他可得到如 112222 或 111122 依卡片升序排列的隊伍。有時僅剩一組,例如 1111 或 222。

FJ 也很懶。要正確分組最少須改幾張卡片?只能改號碼,不得重排乳牛。

輸入格式

從標準輸入讀取。

  • 第 1 行:整數 $N$。
  • 第 $2,\ldots,N+1$ 行:第 $i+1$ 行以整數 $D_{i}$ 描述乳牛 $i$ 的飯組偏好。

輸出格式

寫入標準輸出。

  • 第 1 行:整數,為 Farmer John 完成上述分組須改的最少卡片數。

範例

輸入格式 1

7
2
1
1
1
2
2
1

輸出格式 1

2

說明

七頭乳牛,除三頭外,目前都偏好飯組 $1$。

修改第一頭和最後一頭的卡片。

題目署名:Ionescu Victor 和 Brian Dean,2007

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.