当前位置:网站首页>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
边栏推荐
- Charles+drony的APP抓包
- cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
- 2022上半年朋友圈都在传的10本书,找到了
- The performance and efficiency of the model that can do three segmentation tasks at the same time is better than maskformer! Meta & UIUC proposes a general segmentation model with better performance t
- [C language] string function
- 手把手教姐姐写消息队列
- Industry case | digital operation base helps the transformation of life insurance industry
- Mathematical analysis_ Notes_ Chapter 11: Fourier series
- 我感觉被骗了,微信内测 “大小号” 功能,同一手机号可注册两个微信
- 脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
猜你喜欢
随机推荐
How many times is PTA 1101 B than a
面试唯品会实习测试岗、抖音实习测试岗【真实投稿】
【Base64笔记】「建议收藏」
ES6 note 1
10 schemes to ensure interface data security
GSAP animation library
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
鸿蒙智能家居【1.0】
Kirk borne's selection of learning resources this week [click the title to download directly]
二叉树的基本概念和性质
Reject policy of thread pool
[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
SD_ DATA_ RECEIVE_ SHIFT_ REGISTER
Complete e-commerce system
Differences between rip and OSPF and configuration commands
Calculation of torque target value (ftorque) in servo torque control mode
博睿数据入选《2022爱分析 · IT运维厂商全景报告》
App capture of charles+drony
POJ 2392 Space Elevator
LeetCode 890(C#)