QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#21029. في غير مكانها

İstatistikler

يشعر 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.