当前位置:网站首页>Uvalive – 4621 CAV greed + analysis "suggestions collection"
Uvalive – 4621 CAV greed + analysis "suggestions collection"
2022-07-07 19:12:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
The main idea of the topic : There's a map of the cave , To store water in this cave , The water is required not to touch the top of the cave . Now give the top position and ground height of each position . How much water can I put at most
Their thinking : According to the laws of Physics , Every continuous section with water , The water level must be equal So we can calculate the height of water level in the same continuous interval , This water level is equal to the height of the top of the lowest cave . Based on this , Update from left to right , Then update from right to left , You can get the water level height of each position
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1000010;
const int INF = 0x3f3f3f3f;
int s[N], p[N], n;
void init() {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
for(int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
}
int solve() {
int t = INF;
for(int i = 0; i < n; i++) {
t = min(t, s[i]);
t = max(t, p[i]);
s[i] = t;
}
t = INF;
for(int i = n - 1; i >= 0; i--) {
t = min(t, s[i]);
t = max(t, p[i]);
s[i] = t;
}
int ans = 0;
for(int i = 0; i < n; i++)
ans += s[i] - p[i];
return ans;
}
int main() {
int test;
scanf("%d", &test);
while(test--) {
init();
printf("%d\n", solve());
}
return 0;
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116603.html Link to the original text :https://javaforall.cn
边栏推荐
- ES6 note 1
- Kirk borne's selection of learning resources this week [click the title to download directly]
- Wireshark analyzes packet capture data * cap
- A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
- 2022年推荐免费在线接收短信平台(国内、国外)
- 3. About cookies
- Charles+drony的APP抓包
- Usage of PHP interview questions foreach ($arr as $value) and foreach ($arr as $value)
- Golang client server login
- 【剑指 Offer】59 - I. 滑动窗口的最大值
猜你喜欢
Reuse of data validation framework Apache bval
Calculation of torque target value (ftorque) in servo torque control mode
Version 2.0 of tapdata, the open source live data platform, has been released
Nat address translation
App capture of charles+drony
gsap动画库
DeSci:去中心化科学是Web3.0的新趋势?
I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
基于图像和激光的多模态点云融合与视觉定位
博睿数据入选《2022爱分析 · IT运维厂商全景报告》
随机推荐
Wireshark analyzes packet capture data * cap
App capture of charles+postern
POJ 2392 Space Elevator
高温火烧浑不怕,钟薛高想留清白在人间
[Base64 notes] [suggestions collection]
Calculation of torque target value (ftorque) in servo torque control mode
String type, constant type and container type of go language
前首富,沉迷种田
NAT地址转换
"Decryption" Huawei machine vision Corps: Huawei is moving up and the industry is moving forward
能同时做三个分割任务的模型,性能和效率优于MaskFormer!Meta&UIUC提出通用分割模型,性能优于任务特定模型!开源!...
国内的软件测试会受到偏见吗
LeetCode 497(C#)
Continuous test (CT) practical experience sharing
2022-07-04 matlab读取视频帧并保存
标准ACL与扩展ACL
PTA 1102 teaching Super Champion volume
博睿数据入选《2022爱分析 · IT运维厂商全景报告》
二叉树的基本概念和性质
99% of people don't know that privatized deployment is also a permanently free instant messaging software!