Topic 1386: The smallest number of rotating arrays of swords finger offer08

Source: Internet
Author: User

Http://ac.jobdu.com/problem.php?pid=1386

WA got a pitch because it didn't take into account its own orderly situation.

Seems to be CUHK once the face of the test, was prepared to CUHK interview at the time of others blog saw.

Thought two points, the simple idea I have, but the special situation did not consider well.

*mid and *first, *mid and *end, *mid>=*first, illustrate *mid now in the orderly part of the front.

*mid<*first, indicating *mid in the back of the ordered part.

It's okay to modify first and end.

There are two special cases:
1. The order of itself

2, 1 1 1 0 1

1 0 1) 1 1

This example

#include <cstdio> #include <cstring> #include <iostream> #include <cstdio> #include < algorithm>using namespace Std;const int SIZE = 1000000+1;int n;int num[size];void specialjudge (int s, int e) {int V    = Num[s];    for (int i=s+1;i<=e;i++) {v = min (num[i], V); } printf ("%d\n", V);}    void Solve () {int firstptr=0, endptr=n-1;        if (Num[endptr]>num[firstptr]) {printf ("%d\n", Num[firstptr]);    return;        } while (Firstptr < endptr && firstptr! = endPtr-1) {int mid = (firstptr + endptr) >>1;            if (num[mid] = = Num[firstptr] && Num[mid] = = Num[endptr]) {Specialjudge (firstptr, endptr);        Return        } if (Num[mid]>=num[firstptr]) {firstptr = mid;        }else{endptr = mid; }} printf ("%d\n", Num[endptr]);}    int main () {//freopen ("08.txt", "R", stdin); while (~SCANF ("%d", &n)) {for (int i=0;i<n;i++) {scanf ("%d", &num[i]);    } solve (); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Topic 1386: The smallest number of rotating arrays of swords finger offer08

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.