water是啥

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了water是啥相关的知识,希望对你有一定的参考价值。

water ['wɔtɚ]
[词典释义]n. 1. 水 2. (江、湖、海等的)水体;大片的水[P1] 3. 水位,潮位 4. (生物体内的...
vt. 1. 给...浇水,灌溉 2. 给...水;给...供水 3. 搀水冲淡,加水稀释
vi. 1. 流泪;流口水 2. (船等)加水 3. (动物)饮水
[网络释义]water 1.水渍牢度 2.水,水剂 3.水②【动】加水 4.
参考技术A 名词:水 a cup of water
动词:浇水,浇花 water the flowers
参考技术B 水;浇水 参考技术C 是水的意思 参考技术D 中文意思是水

LeetCode 755. Pour Water

原题链接在这里:https://leetcode.com/problems/pour-water/description/

题目:

We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After Vunits of water fall at index K, how much water is at each index?

Water first drops at index K and rests on top of the highest terrain or water at that index. Then, it flows according to the following rules:

  • If the droplet would eventually fall by moving left, then move left.
  • Otherwise, if the droplet would eventually fall by moving right, then move right.
  • Otherwise, rise at it‘s current position.

Here, "eventually fall" means that the droplet will eventually be at a lower level if it moves in that direction. Also, "level" means the height of the terrain plus any water in that column.

 

We can assume there‘s infinitely high terrain on the two sides out of bounds of the array. Also, there could not be partial water being spread out evenly on more than 1 grid block - each unit of water has to be in exactly one block.

 

Example 1:

Input: heights = [2,1,1,2,1,2,2], V = 4, K = 3
Output: [2,2,2,3,2,2,2]
Explanation:
#       #
#       #
##  # ###
#########
 0123456    <- index

The first drop of water lands at index K = 3:

#       #
#   w   #
##  # ###
#########
 0123456    

When moving left or right, the water can only move to the same level or a lower level.
(By level, we mean the total height of the terrain plus any water in that column.)
Since moving left will eventually make it fall, it moves left.
(A droplet "made to fall" means go to a lower height than it was at previously.)

#       #
#       #
## w# ###
#########
 0123456    

Since moving left will not make it fall, it stays in place.  The next droplet falls:

#       #
#   w   #
## w# ###
#########
 0123456  

Since the new droplet moving left will eventually make it fall, it moves left.
Notice that the droplet still preferred to move left,
even though it could move right (and moving right makes it fall quicker.)

#       #
#  w    #
## w# ###
#########
 0123456  

#       #
#       #
##ww# ###
#########
 0123456  

After those steps, the third droplet falls.
Since moving left would not eventually make it fall, it tries to move right.
Since moving right would eventually make it fall, it moves right.

#       #
#   w   #
##ww# ###
#########
 0123456  

#       #
#       #
##ww#w###
#########
 0123456  

Finally, the fourth droplet falls.
Since moving left would not eventually make it fall, it tries to move right.
Since moving right would not eventually make it fall, it stays in place:

#       #
#   w   #
##ww#w###
#########
 0123456  

The final answer is [2,2,2,3,2,2,2]:

    #    
 ####### 
 ####### 
 0123456 

 

Example 2:

Input: heights = [1,2,3,4], V = 2, K = 2
Output: [2,3,3,4]
Explanation:
The last droplet settles at index 1, since moving further left would not cause it to eventually fall to a lower height.

 

Example 3:

Input: heights = [3,1,3], V = 5, K = 1
Output: [4,4,4]

 

Note:

  1. heights will have length in [1, 100] and contain integers in [0, 99].
  2. V will be in range [0, 2000].
  3. K will be in range [0, heights.length - 1].

题解:

根据题目模拟过程,每次找出适合防水的index, 让后把此处高度+1. 重复水量次数.

Time Complexity: O(V*n). n = heights.length.

Space: O(1).

AC Java:

 1 class Solution {
 2     public int[] pourWater(int[] heights, int V, int K) {
 3         if(heights == null || K >= heights.length){
 4             return heights;
 5         }
 6         
 7         while(V-->0){
 8             int index = findPosition(heights, K);
 9             if(index>=0 && index<heights.length){
10                 heights[index]++;
11             }
12         }
13         
14         return heights;
15     }
16     
17     private int findPosition(int [] nums, int start){
18         int res = start;
19         int l = start;
20         int r = start;
21         
22         while(r<nums.length-1 && nums[r+1]<=nums[r]){
23             if(nums[r+1]<nums[r]){
24                 res = r+1;
25             }
26             r++; 
27         }
28         
29         while(l>=1 && nums[l-1]<=nums[l]){
30             if(nums[l-1]<nums[l]){
31                 res = l-1;
32             }
33             l--;
34         }
35 
36         return res;
37     }
38 }

 

以上是关于water是啥的主要内容,如果未能解决你的问题,请参考以下文章

water purification system是啥意思

water和waters的区别

跪求noip2010普及 接水问题(water)程序代码,望哪位高手帮帮忙谢谢啊。。。

42. Trapping Rain Water *HARD*

42. Trapping Rain Water

water沃特世 是哪国公司