本帖最后由 liuzhengyuan 于 2020-5-11 12:58 编辑
我突然发现这样更快,65ms //luogo_p1007
#include<iostream>
using namespace std;
int main()
{
int l, solnum;
cin>>l;
cin>>solnum;
int solpos, maxtime, mintime;
//solpos 记录士兵的位置
maxtime = 0;
mintime = 0;
for(int i=0; i<solnum; i++)
{
cin>>solpos;
int maxtemp, mintemp;
maxtemp = max(l-solpos+1, solpos);
mintemp = min(l-solpos+1, solpos);
if(maxtime < maxtemp)
{
maxtime = maxtemp;
}
if(mintime < mintemp) //这里要用 <
{
mintime = mintemp;
}
}
cout<<mintime<<' '<<maxtime;
return 0;
}
|