Water The Garden

 思路:通过计算水龙头之间的距离,得到最小值;

最左边和左右边的水龙头单独计算,中间的水龙头因为水流靠拢,所以距离要除以2

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<queue>
 6 #include<stack>
 7 #include <bitset>
 8 #include<set>
 9 #include<map>
10 #include<unordered_map>
11 #include<vector>
12 #include<cmath>
13 #include<string>
14 using namespace std;
15 typedef long long ll;
16 int t, n, k;
17 int x[200];
18 int res;
19 int main() {
20     cin >> t;
21     while (t--) {
22         cin >> n >> k;
23         for (int i = 1; i <= k; i++) {
24             cin >> x[i];
25         }
26         //第一个水龙头的距离
27         int t = x[1];
28         res = x[1];
29         //考虑水龙头之间的距离,计算与前一个水龙头的距离
30         for (int i = 2; i <= k; i++) {
31             //两个水龙头往中间靠拢,时间减半
32             res = max(res, (x[i] - t) / 2 + 1);
33             t = x[i];
34         }
35         //比较最后一个水龙头
36         res = max(res, n - t + 1);
37         cout << res << endl;
38     }
39     return 0;
40 }

 

posted @ 2020-07-20 22:34  吉吉的奥利奥  阅读(200)  评论(0编辑  收藏  举报