链接:https://ac.nowcoder.com/acm/contest/1069/D

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 32768K,其他语言65536K

64bit IO Format: %lld

题目描述

The oppressively hot summer days have raised the cows' clamoring to its highest level. Farmer John has finally decided to build an artificial lake. For his engineering studies, he is modeling the lake as a two-dimensional landscape consisting of a contiguous sequence of N soon-to-be-submerged levels (1 <= N <= 100,000) conveniently numbered 1..N from left to right.
Each level i is described by two integers, its width W_i (1 <= W_i <= 1,000) and height (like a relative elevation) H_i (1 <= H_i <= 1,000,000). The heights of FJ's levels are unique. An infinitely tall barrier encloses the lake's model on the left and right. One example lake profile is shown below.
* * :
* * :
* * 8
* *** * 7
* *** * 6
* *** * 5
* ********** 4 <- height
* ********** 3
*************** 2
*************** 1
Level | 1 |2| 3 | In FJ's model, he starts filling his lake at sunrise by flowing water into the bottom of the lowest elevation at a rate of 1 square unit of water per minute. The water falls directly downward until it hits something, and then it flows and spreads as room-temperature water always does. As in all good models, assume that falling and flowing happen instantly. Determine the time at which each elevation's becomes submerged by a single unit of water.
WATER WATER OVERFLOWS
| |
* | * * | * * *
* V * * V * * *
* * * .... * *~~~~~~~~~~~~*
* ** * *~~~~** : * *~~~~**~~~~~~*
* ** * *~~~~** : * *~~~~**~~~~~~*
* ** * *~~~~**~~~~~~* *~~~~**~~~~~~*
* ********* *~~~~********* *~~~~*********
*~~~~********* *~~~~********* *~~~~*********
************** ************** **************
************** ************** ************** After 4 mins After 26 mins After 50 mins
Lvl 1 submerged Lvl 3 submerged Lvl 2 submerged Warning: The answer will not always fit in 32 bits.

输入描述:

* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 describes level i with two space-separated integers: WiW_iWi​ and HiH_iHi​

输出描述:

* Lines 1..N: Line i contains a single integer that is the number of minutes that since sunrise when level #i is covered by water of height 1.
示例1

输入

3
4 2
2 7
6 4

输出

4
50
26

说明

Three levels just as in the example above.  Water will fill the first level because it is the lowest.
As in the illustrations above.

模拟
  每次找到当前最低的可以被灌水的平台填灌
  然后合并更新

代码
  1 #include <bits/stdc++.h>
2 #include <iostream>
3 #include <cstring>
4 #include <stack>
5 #include <cstdlib>
6 #include <queue>
7 #include <cmath>
8 #include <cstdio>
9 #include <algorithm>
10 #include <string>
11 #include <vector>
12 #include <list>
13 #include <iterator>
14 #include <set>
15 #include <map>
16 #include <utility>
17 #include <iomanip>
18 #include <ctime>
19 #include <sstream>
20 #include <bitset>
21 #include <deque>
22 #include <limits>
23 #include <numeric>
24 #include <functional>
25 #define gc getchar()
26 #define mem(a) memset(a,0,sizeof(a))
27 #define mod 1000000007
28 #define sort(a,n,int) sort(a,a+n,less<int>())
29 #define fread() freopen("in.in","r",stdin)
30 #define fwrite() freopen("out.out","w",stdout)
31
32 #define PI acos(-1.0)
33 #define N 100005
34 #define MOD 2520
35 #define E 1e-12
36
37 typedef long long ll;
38 typedef char ch;
39 typedef double db;
40 const long long INF = 0x3f3f3f3f3f3f3f3f;
41
42 using namespace std;
43
44
45 struct node
46 {
47 ll w , h;
48 int l , r;
49 }a[N];
50
51 int n = 0;
52 long long res[N] = {0};
53
54 int lowest()
55 {
56 ll minv = INF , pos = 0;
57 for(int i = 1;i <= n;i++)
58 if(a[i].h < minv)
59 {
60 minv = a[i].h;
61 pos = i;
62 }
63 return pos;
64 }
65 int update(int position)
66 {
67 for(int i = 0;i<n;i++)
68 {
69 int left = a[position].l , right = a[position].r;
70
71 if(a[left].h < a[position].h)
72 position = left;
73 else if(a[right].h < a[position].h)
74 position = right;
75 else
76 return position;
77 }
78 }
79 void guanshui(int position)
80 {
81 int counter = 1;
82 long long sum = 0;
83 while(counter <= N)
84 {
85 counter++;
86 sum += a[position].w;
87 res[position] = sum;
88 int l = a[position].l , r = a[position].r;
89 sum += (min(a[l].h , a[r].h) - a[position].h - 1) * a[position].w;
90
91 a[l].r = r;
92 a[r].l = l;
93
94 if(a[l].h < a[r].h)
95 {
96 a[l].w += a[position].w;
97 position = l;
98 }
99 else
100 {
101 a[r].w += a[position].w;
102 position = r;
103 }
104 position = update(position);
105 }
106 }
107 int main()
108 {
109 cin >> n;
110 int position = 0;
111 for(int i = 1;i <= n;i++)
112 {
113 cin >> a[i].w >> a[i].h;
114 }
115 for(int i = 0;i <= n+1;i++)
116 {
117 a[i].l = i-1;
118 a[i].r = i+1;
119 }
120 a[0].w = 1;
121 a[0].h = INF;
122
123 a[n+1].w = 1;
124 a[n+1].h = INF;
125
126 position = lowest();
127 guanshui(position);
128 for(int i = 1;i <= n;i++)
129 {
130 cout << res[i] << endl;
131 }
132 return 0;
133 }

nowcoder假日团队赛8 D-Artificial Lake的更多相关文章

  1. 【Contest】Nowcoder 假日团队赛1 题解+赛后总结

    比赛链接 通过顺序:\(B\rightarrow D\rightarrow I\rightarrow J\rightarrow G\rightarrow H \rightarrow A \righta ...

  2. 牛客假日团队赛1 A.蹄球锦标赛

    链接: https://ac.nowcoder.com/acm/contest/918/A 题意: 为了准备即将到来的蹄球锦标赛,Farmer John正在训练他的N头奶牛(方便起见,编号为1-N,其 ...

  3. 牛客假日团队赛1 J.分组

    链接: https://ac.nowcoder.com/acm/contest/918/J 题意: 在Farmer John最喜欢的节日里,他想要给他的朋友们赠送一些礼物.由于他并不擅长包装礼物,他想 ...

  4. 牛客假日团队赛1 I.接机

    链接: https://ac.nowcoder.com/acm/contest/918/I 题意: 一场别开生面的牛吃草大会就要在Farmer John的农场举办了! 世界各地的奶牛将会到达当地的机场 ...

  5. 牛客假日团队赛1 G.Superbull

    链接: https://ac.nowcoder.com/acm/contest/918/G 题意: Bessie and her friends are playing hoofball in the ...

  6. 牛客假日团队赛1 D.Promotion Counting

    链接: https://ac.nowcoder.com/acm/contest/918/D 题意: Bessie the cow is helping Farmer John run the USA ...

  7. 牛客假日团队赛1B.便便传送门(一)

    链接:https://ac.nowcoder.com/acm/contest/918/B 题意: Farmer John最讨厌的农活是运输牛粪.为了精简这个过程,他制造了一个伟大的发明:便便传送门!与 ...

  8. 牛客假日团队赛2 H.奶牛排序

    链接: https://ac.nowcoder.com/acm/contest/924/H 题意: 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾 ...

  9. 牛客假日团队赛2 G.CountyFairEvents

    链接: https://ac.nowcoder.com/acm/contest/924/G 题意: Farmer John has returned to the County Fair so he ...

  10. 牛客假日团队赛2 F.跳跃

    链接: https://ac.nowcoder.com/acm/contest/924/F 题意: Farmer John为了满足奶牛对美的享受而安装了人工湖.矩形的人工湖分成M行N列(1 <= ...

随机推荐

  1. Github Copilot 实战: 从零开始用AI写一个OCR工具 (1)

    最近AI很火,咱也尝试一下由浅入深探索一下 Github Copilot 的能力和底限. 使用的环境是 Windows11 + Microsoft Visual Studio Enterprise 2 ...

  2. 基于vue3项目开发+MonacoEditor实现外部引入依赖,界面化所见即所得

    最近一个项目中,基于vue3开发,想开发一个在线管理组件库的功能,具体业务实现: 1. 在私库Nexus上传组件包: 2. 然后用UNPKG实现路径访问在线解压文件: 3. 解压文件上传到gitee组 ...

  3. NSMutableDictionary 的内存布局

    有关NSDictionary的内存布局,可以参看<NSDictionary 的内存布局>. 1 类图 和<NSDictionary 的内存布局>中的类图相比较,本章类图多了2个 ...

  4. FPGA使用两个HC595驱动8位数码管

    FPGA使用两个HC595驱动8位数码管 本文章给出使用FPGA3根线来驱动8位数码管的示例代码,输入为disp_data,共7*8=56位,输出输入如图所示. 硬件方面参数 该程序只能控制数码管的7 ...

  5. 你了解Java线程池原理吗?

    简要回答 线程池是一种池化技术,用于预先创建并管理一组线程,避免频繁创建和销毁线程的开销,提高性能和响应速度 它几个关键的配置包括:核心线程数.最大线程数.空闲存活时间.工作队列.拒绝策略 主要工作原 ...

  6. DBA必备神器:让Oracle关库不再心惊胆战!

    我们的文章会在微信公众号"Oracle恢复实录"和博客网站同步更新,欢迎关注收藏.也欢迎大家转载,但请在文章开始处标注文章出处,谢谢! 由于博客中包含大量代码,建议通过网页浏览以获 ...

  7. CRM 价格更新

    FUNCTION zcrm_reprice_bt. *"------------------------------------------------------------------- ...

  8. 替换GitLab的方案之Gitea

    概述 官网:https://docs.gitea.com/zh-cn/ GitHub地址:https://github.com/go-gitea/gitea Gitea 是一个轻量级的 DevOps ...

  9. CAE和CAD的区别

    CAE又被叫做"计算机辅助工程",而CAD则是"计算机辅助设计".虽然CAE和CAD是两种不同的技术,但它们却有着一定联系.在如今这个遍布科技与狠活的社会里,C ...

  10. UFT API