AC Code:
#include <iostream>
#include <algorithm>
using namespace std;
struct Days_Destroyed
{
int i;//tile的序号
int day;//要使 i-th tile 被毁的日数
}a[1001];
bool dest[1001]; //记录是否被毁,默认为假,即木有被毁
int cmp(const void *a,const void *b)
{
struct Days_Destroyed* aa=(Days_Destroyed*)a;
struct Days_Destroyed* bb=(Days_Destroyed*)b;
return aa->day-bb->day;
}
int main()
{
int n,MaxDays,j;
while(cin>>n)
{
MaxDays=1;
for(j=1;j<=n;j++)
{
cin>>a[j].day;
a[j].i=j;
dest[j]=false;
}
qsort(a+1,n,sizeof(a[0]),cmp);//快速排序
for(j=1;j<=n;j++)
{
//如果是第一或最后一个tile被毁,又或相邻两个tile之一被毁,当前tile就不能再被毁
if(a[j].i==1 || a[j].i==n || dest[a[j].i-1] || dest[a[j].i+1])
{
MaxDays=a[j].day;//注意不能直接break,要先执行这一步
break;
}
else
{
MaxDays=a[j].day;
dest[a[j].i]=true;//标记为已被破坏
}
}
cout<<MaxDays<<endl;
}
return 0;
}