Nine degrees OJ 1398 moves (array, analog)

Source: Internet
Author: User

Topic 1398: Number of moves

time limit:1 seconds

Memory limit:32 MB

Special question: No

submitted:1375

Resolution:369

Title Description:

It is well known that JOBDU's Jobbala company is an IT company known for its individuality and its own people. During the 50 anniversary of the founding of Jobbala company, the CEO of the company organizes all staff mountaineering tours. According to the usual habit, the tour guide usually asks the visitor to arrange according to the height from low to high, but considers this jobbala the number is too many, the sorting is very time-consuming. Therefore, the tour guide thought, asked Jobbala staff can be casually platoon, but must ensure that the first queue is the shortest queue, the last queue is the highest in the queue. For example: queue {1, 4, 3, 2, 2, 5} are eligible queues, {1, 4, 2, 3, 2, 5} are also compliant, while {2, 1, 2, 3, 4, 5} are wrong. What is the minimum number of 22 exchanges for any queue to be able to meet the requirements of the tour guide?

Input:

Enter more than one set of test cases, each of which is 2 rows.

The first line consists of an integer n (2<=n<=200) representing the number of people, and the next line consists of n integers a1, A2, ... an (1<=ai<=200) represents the initial arrangement of N employees.

Output:

corresponding to each test case, according to the requirements of the tour guide, the output requires a minimum of 22 times.

Sample input:
289 88455 88) 1 2
Sample output:
13
Tips:
In case 2, the minimum number of moves is three: (1 2)--(1 2 1)---(2, 1 55)

#include <stdio.h>int n;int t;int ans;int max=-1;int min=0x3f3f3f3f;int max_index;int MIN_INDEX;int Main (int argc,    Char *argv[]) {//freopen ("1398.in", "R", stdin);    Std::ios::sync_with_stdio (FALSE);    Std::cin.tie (0);        while (~SCANF ("%d", &n)) {max=-1;        min=0x3f3f3f3f;        ans=0;            for (int i=1;i<=n;++i) {scanf ("%d", &t);                if (t<min) {min=t;                min_index=i;//the smallest i} if (T>=max) {max=t;     max_index=i;//with the same maximum value, the largest subscript pit}}//cout<< "Min_index is" <<min_index//        << "Max_index is" <<max_index//<< "\ n";        if (min_index<max_index) {ans=min_index+n-1-max_index;        } else {ans=min_index+n-1-max_index-1;    } printf ("%d\n", ans); } return 0;}


Nine degrees OJ 1398 moves (array, analog)

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.