#include <cstdio> //1.該題目來自 http://ac.jobdu.com/problem.php?pid=1386 //2.目前任然有數據未經過, 注意333123 爲合法輸入 //3.樸素可直接AC,但這裏重點考察二分 #define MAXSIZE 1000010 #define MAXVAL 10000010 int elementTots; int elements[MAXSIZE]; int main() { int ans; while( EOF != scanf("%d", &elementTots)){ for(int currPos = 1; currPos <= elementTots; currPos++){ scanf("%d", &elements[currPos]); } int lftPos = 1; int rhtPos = elementTots; if(elements[lftPos] < elements[rhtPos]|| 1 == elementTots){ ans = elements[lftPos]; }else{ while(lftPos < rhtPos){ if(1 == rhtPos - lftPos){ ans = elements[rhtPos]; break; } int midPos = lftPos + ( (rhtPos - lftPos) >> 1); if(elements[midPos] >= elements[lftPos]){ lftPos = midPos; continue; } if(elements[midPos] < elements[rhtPos]){ rhtPos = midPos; continue; } if(elements[midPos] == elements[rhtPos]){ rhtPos = midPos - 1; } } } printf("%d\n", ans); } return 0; }