传送门
https://vjudge.net/contest/279162#problem/C
说一个毒瘤的算法 对于每个格子挨个判断找出所有结果中的最大值就可以了,然后理所应当的超时了
正解:先把输入的水龙头的位置排列(sort天下无敌),然后每两个水龙头中间所有格子需要的时间的最大值其实就是中间的一个/两个格子的值,这样就减少很多计算量,当然边上那两个要特别计算一下.
AC代码如下:
/****************************
*
* Name :C - Water The Garden
* Time :2019-1-20 9:23:32
* Author :大哥
* Type :思维
* 版权所有_翻版不管
*
****************************
*/
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<iomanip>
#include<iostream>
#include<map>
#include<bitset>
#include<cassert>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<deque>
#include<list>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
//ios::sync_with_stdio(false);
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+10;
const int maxm = 100+10;
struct piont{
int x;
int y;
};
#define N 10000
#define M 100
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif
int t,n,m,arr[200];
cin>>t;
while (t--){
cin>>n>>m;
for (int i = 0; i<m; i++){
cin>>arr[i];
}
sort(arr,arr+m);
int maxl = max(arr[0],n+1-arr[m-1]);
for (int i = 0; i<m-1; i++){
maxl = max(maxl,1+(arr[i+1]-arr[i]-1)/2+(arr[i+1]-arr[i]-1)%2); }
cout<<maxl<<endl;
}
return 0;
}