zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    a Makefile
    Fedora的一些个人配置
    开机默认命令行
    挂载iso文件
    Vi不显示insert
    beego 框架基本使用 && 知识点整理
    kafka的安装及使用(单节点)
    Go 实现短 url 项目
    晓看天色暮看云,铁马冰河入梦来
    Go net/http,web server
  • 原文地址:https://www.cnblogs.com/0211ji/p/13345596.html
Copyright © 2011-2022 走看看