zoukankan      html  css  js  c++  java
  • D

    细分的话有两种情况,一种就是头和尾,时间就是距离,(这里的时间最后统一加一,严格来说时间是距离加一,因为填满当前位置需要一秒,下一秒才可以真正所谓的扩展),另一种考虑水龙头之间,例如距离为1,则时间就是1,距离为2时间为1距离为3时间就是2,规律很明了:距离对2取余,有余数则距离/2+1,否则距离/2。枚举水龙头之间的距离即可。(取最大时间,道理你肯定懂)

    AC代码:

    #include <iostream>
    
    using namespace std;
    const int maxn = 200;
    int book[maxn];
    int main(){
        int t;
        cin>>t;
        while(t--){
            int n, k;
            int ans=0;
            cin>>n>>k;
            for(int i=1;i<=k;i++)
                cin>>book[i];
            ans=max(book[1]-1,n-book[k]);//考虑两边的情况
            for(int i=2;i<=k;i++){//中间的情况
                int temp=book[i]-book[i-1]-1;  //防止距离为1的情况
                if(temp%2)
                    temp=temp/2+1;
                else
                    temp=temp/2;
                ans=max(ans,temp);
            }
            cout<<ans+1<<endl;
        }
        return 0;
    }

    It is winter now, and Max decided it's about time he watered the garden.

    The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.

    The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.

    The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.

    Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

    Input

    The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200).

    Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively.

    Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each condition xi - 1 < xi holds.

    It is guaranteed that the sum of n over all test cases doesn't exceed 200.

    Note that in hacks you have to set t = 1.

    Output

    For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

    Example

    Input

    3
    5 1
    3
    3 3
    1 2 3
    4 1
    1
    

    Output

    3
    1
    4
    

    Note

    The first example consists of 3 tests:

    1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
    2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
    3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.
  • 相关阅读:
    知方可补不足~Sqlserver发布订阅与sql事务的关系
    基础才是重中之重~泛型类的静态构造方法可不是只执行一次呀
    EF架构~通过EF6的DbCommand拦截器来实现数据库读写分离~终结~配置的优化和事务里读写的统一
    EF架构~通过EF6的DbCommand拦截器来实现数据库读写分离~再续~添加对各只读服务器的心跳检测
    windows服务的创建、安装和调试
    Axure RP 实践.1
    实习第一天之数据绑定:<%#Eval("PartyName")%>'
    Hadoop云计算大数据书籍分享
    Android利用setLayoutParams在代码中调整布局(Margin和居中)
    TopCoder中插件的用法
  • 原文地址:https://www.cnblogs.com/UUUUh/p/10284076.html
Copyright © 2011-2022 走看看