Educational Codeforces Round 37 (Rated for Div. 2) A. Water The Garden ---- 思维

版权声明:本文为博主原创文章,转载请预先通知博主(〃'▽'〃)。 https://blog.csdn.net/m0_37624640/article/details/82776012

题目传送门

做法:

  • 枚举每个花床,看看哪个水龙头离他最近,然后找出能保证覆盖所有的水龙头即可。即就是先最小再最大。

AC代码:

#include<bits/stdc++.h>
#define IO          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb(x)       push_back(x)
#define sz(x)       (int)(x).size()
#define sc(x)       scanf("%d",&x)
#define pr(x)       printf("%d\n",x)
#define abs(x)      ((x)<0 ? -(x) : x)
#define all(x)      x.begin(),x.end()
#define mk(x,y)     make_pair(x,y)
#define debug       printf("!!!!!!\n")
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const double PI = 4*atan(1.0);
const int maxm = 1e8+5;
const int maxn = 1e5+5;
const int INF = 0x3f3f3f3f;
inline int read()
{
    char x;
    int u,flag = 0;
    while(x = getchar(),x<'0' || x>'9') if(x == '-') flag = 1;
    u = x-'0';
    while(x = getchar(),x>='0' && x<='9') u = (u<<3)+(u<<1)+x-'0';
    if(flag) u = -u;
    return u;
}
int tap[205];
int main()
{
    #ifdef LOCAL_FILE
    freopen("in.txt","r",stdin);
    #endif // LOCAL_FILE
    int t;
    t = read();
    int idx = 1;
    while(t--) //不是区间而是区间上的点!!
    {
        int n,k;
        n = read();
        k = read();
        for(int i=0;i<k;i++) tap[i] = read();
        int ans = 0;
        for(int i=1;i<=n;i++)
        {
            int mx = INF;
            for(int j=0;j<k;j++) mx = min(mx,abs(tap[j]-i)+1);
            ans = max(ans,mx);
        }
        cout<<ans<<endl;
    }
    #ifdef LOCAL_FILE
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << "ms." << endl;
    #endif // LOCAL_FILE
    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37624640/article/details/82776012