I - March Rain

 1 /*
 2 屋顶有n个洞,用k块板子覆盖所有洞,问最长的一块板子至少是多长。
 3 二分长度,贪心的方式尝试覆盖,把每一块板子都放在刚好能覆盖最左边的洞的最右位置
 4 从而判断某个长度的k块板子能否覆盖所有洞。
 5 */
 6 #include <bits/stdc++.h>
 7 using namespace std;
 8 int d[100010];
 9 int main()
10 {
11     int t;
12     scanf("%d",&t);
13     while(t--)
14     {
15         int n,m;
16         scanf("%d%d",&n,&m);
17         for(int i=0;i<n;i++)
18             scanf("%d",&d[i]);
19         int l=0;
20         int r=d[n-1]/m+1;
21         while(l<=r)
22         {
23             int mid=l+(r-l)/2;
24             int x=d[0];
25             int cnt=1;
26             for(int i=1;i<n;i++)
27             {
28                 if(d[i]>=x+mid)
29                 {
30                     x=d[i];
31                     cnt++;
32                 }
33             }
34             if(cnt>m)
35                 l=mid+1;
36             else
37                 r=mid-1;
38         }
39         printf("%d\n",r+1);
40     }
41 }
时间: 2024-12-04 17:28:10

I - March Rain的相关文章

HDU 2389 Rain on your Parade

http://acm.hdu.edu.cn/showproblem.php?pid=2389 题意:给暴风雨到来的时刻,m个人的坐标和单位速度,和n个救生衣的坐标.每个救生衣只能匹配一个人,求最多有多少人可以得到救生衣. 题解:典型二分图最大匹配题型.因为点比较多,使用Hopcroft-Karp算法.讲解:http://blog.csdn.net/wall_f/article/details/8248373 http://www.cnblogs.com/-sunshine/archive/201

407. Trapping Rain Water II

Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining. Note: Both m and n are less than 110. The height of each unit cell is greater th

某校内题 rain

Task 3. 雨中冒险 ( rain.cpp/c/pas) [ 问题描述] 有 n 个节点,标号为 1..n. m 条双向公路连接着这些节点,其中第 i 条公路 连接着 u_i 和 v_i,从一端走到另一端需要 w_i 秒.现在,小 Y 打算从学校回到 家里. 学校是节点 1,小 Y 家是节点 n,保证存在至少一条从节点 1 到节点 n 的路 径. 在第 0 秒,小 Y 身处节点 1,他的目标是尽早到达节点 n.根据天气预报, 接下来会有 k 次暴雨,第 i 次暴雨的时间为第 l_i 秒至第

LeetCode42 Trapping Rain Water

题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map is represented

有意思的数学题:Trapping Rain Water

LeetCode传送门 https://leetcode.com/problems/trapping-rain-water/ 目标:找出积木能容纳的水的“面积”,如图中黑色部分是积木,蓝色为可容纳水的部分 假设:积木宽度均为1 输入:各个积木的高度 输出:所有积木能容纳水的“面积” 思考过程 1. 逐一求积木的间隔似乎不太容易.特别对于图中3-7积木间的容积,如果可以先求底部(4-6间)的容积,当求解上层(3-7)的容积时,还需要做额外的处理,如减掉底部的高度. 2. 既然如此,可否先求出3-7

[LeetCode][JavaScript]Trapping Rain Water

Trapping Rain Water Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map

[LintCode] Trapping Rain Water II

Trapping Rain Water II Given n x m non-negative integers representing an elevation map 2d where the area of each cell is 1 x 1, compute how much water it is able to trap after raining. Example Given 5*4 matrix [12,13,0,12] [13,4,13,12] [13,8,10,12] [

42. Trapping Rain Water

题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map is represented

leetcode 【 Trapping Rain Water 】python 实现

题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. The above elevation map is represented