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