1683 car restructuring, 1683 restructuring

Source: Internet
Author: User

1683 car restructuring, 1683 restructuring

Blog: doubleq. win

1683 car restructuring

 

Time Limit: 1 s space limit: 1000 KB title level: Silver QuestionDescription Description

There is a bridge next to an old railway station, and its bridge deck can rotate horizontally around the bridge pier in the center of the river. Employees at a station can find that the length of the bridge can accommodate up to two carriage lines. If the bridge is rotated 180 degrees, they can switch the positions of the two adjacent carriage lines, this method can be used to re-arrange the carriage order. So he was responsible for using the bridge to sort the railway cars on a small to large basis. After he retired, the railway station decided to automate the work. One of the important tasks was to compile a program, input the initial carriage order, and calculate the minimum number of steps to sort the carriages.

Input description Input Description

The input file contains two rows of data. The first row is the total number of trains (N (not greater than 10000), and the second row is N different numbers, indicating the initial order of trains.

Output description Output Description

A piece of data is the minimum number of rotations.

Sample Input Sample Input

4

4 3 2 1

Sample output Sample Output

6

 1 #include<iostream> 2 using namespace std; 3 int a[10001]; 4 int tot=0; 5 int main() 6 { 7     int n; 8     cin>>n; 9     for(int i=1;i<=n;i++)10     {11         cin>>a[i];12     }13     for(int i=1;i<=n-1;i++)14     {15         for(int j=1;j<=n-1;j++)16         {17             if(a[j]>a[j+1])18             {19                 swap(a[j],a[j+1]);20                 tot++;21             }22         }23     }24     cout<<tot;25     return 0;26 } 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.