AlgorithmOJ
Problem
Local Problems
All Problems
Problem Category
Status
Contest
Standard Contests
Replay Contests
Virtual Contests
Ranklist
More...
News
About
F.A.Q
Recent Contests
Coming Soon...
Login
Register
2026-07-24 20:08:32
最少的交换
Time Limit:
1000ms
Memory Limit:
32768KB
64-bit integer IO format:
%lld
Java class name:
Main
Prev
Submit
Status
Statistics
Next
Font Size:
Description
现在给你一个由n个互不相同的整数组成的序列,现在要求你任意交换相邻的两个数字,使序列成为升序序列,请问最少的交换次数是多少?
Input
输入包含多组测试数据。每组输入第一行是一个正整数n(n<500000),表示序列的长度,当n=0时。
接下来的n行,每行一个整数a[i](0<=a[i]<=999999999),表示序列中第i个元素。
Output
对于每组输入,输出使得所给序列升序的最少交换次数。
Sample Input
5 9 1 0 5 4 3 1 2 3 0
Sample Output
6 0
Author
Admin
Language:
C++ (GCC 5.4.0)
C++11 (GCC 5.4.0)
C++14 (GCC 6.3.0)
C (GCC 5.4.0)
Java (OpenJDK 1.8.0)
Pascal (FPC 3.0.0)
Python2 (2.7.12)
Python3 (3.5.2)
Python3 (3.8.2)
C# (Mono 4.2.1)
Fortran
Perl
Ruby
Ada
SML
Visual C++
Visual C
CLang
CLang++
Theme:
Monokai
Solarized Light
Material
Share Code?
Yes
No
×
Login
Username:
Password:
Cookie:
Never
One Day
One Week
One Month
One Year
×
Register
Username:
Password:
Repeat Password:
Nickname:
School:
Email:
×
News Title
by