QOJ.ac

QOJ

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

#21029. לא במקום

Statistics

מלא שאפתנות, Farmer John מתכנן לנסות דבר שלעולם אינו מצליח לגמרי: לצלם את כל עדר הפרות שלו.

כדי שהתמונה תהיה יפה, הוא רוצה שהפרות יעמדו בשורה מהנמוכה לגבוהה. אך מיד לאחר שהסתדרו, Bessie, שתמיד עושה צרות, יוצאת מהשורה ונכנסת מחדש במקום אחר!

Farmer John רוצה להחליף זוגות פרות כדי שכל העדר ישוב לסדר הנכון. עזרו לו למצוא את מספר ההחלפות המזערי הדרוש.

קלט

שורת הקלט הראשונה מכילה $N$ ($2 \leq N \leq 100$). $N$ השורות הבאות מתארות את גובהי הפרות בסדר שאחרי התזוזה של Bessie. כל גובה הוא מספר שלם בטווח $1 \ldots 1,000,000$. לפרות יכול להיות אותו גובה.

פלט

הדפיסו את מספר החלפות זוגות הפרות המזערי הדרוש לסדר נכון. הפרות המוחלפות אינן חייבות להיות סמוכות בשורה.

דוגמאות

קלט 1

6
2
4
7
7
9
3

פלט 1

3

הסבר

בדוגמה זו Bessie היא בבירור הפרה בגובה 3. FJ משיב את הסדר בשלוש ההחלפות הבאות:

2 4 7 7 9 3 - השורה המקורית
2 4 7 7 3 9 - להחליף את שתי הפרות האחרונות
2 4 3 7 7 9 - להחליף את ה־7 הראשון ואת ה־3
2 3 4 7 7 9 - להחליף את ה־4 ואת ה־3

מחבר הבעיה: Brian Dean

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.