当前位置:网站首页>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
边栏推荐
- Flipping Game(枚举)
- 微信网页调试8.0.19换掉X5内核,改用xweb,所以x5调试方式已经不能用了,现在有了解决方案
- Cloud security daily 220707: Cisco Expressway series and telepresence video communication server have found remote attack vulnerabilities and need to be upgraded as soon as possible
- Complete e-commerce system
- Embedded interview questions (algorithm part)
- [Tawang methodology] Tawang 3W consumption strategy - U & a research method
- PTA 1102 教超冠军卷
- 线程池中的线程工厂
- Scientists have observed for the first time that the "electron vortex" helps to design more efficient electronic products
- Charles+drony的APP抓包
猜你喜欢

将模型的记忆保存下来!Meta&UC Berkeley提出MeMViT,建模时间支持比现有模型长30倍,计算量仅增加4.5%...

Charles+drony的APP抓包

直播预约通道开启!解锁音视频应用快速上线的秘诀

Industry case | digital operation base helps the transformation of life insurance industry

A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)

抢占周杰伦

I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number

Tsinghua, Cambridge and UIC jointly launched the first Chinese fact verification data set: evidence-based, covering many fields such as medical society

完整的电商系统

SlashData开发者工具榜首等你而定!!!
随机推荐
Yunjing network technology interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
Rules for filling in volunteers for college entrance examination
Review of network attack and defense
线程池中的线程工厂
Simple configuration of single arm routing and layer 3 switching
鸿蒙智能家居【1.0】
Reject policy of thread pool
String type, constant type and container type of go language
PTA 1102 教超冠军卷
Reuse of data validation framework Apache bval
POJ 1182 :食物链(并查集)[通俗易懂]
[mime notes]
In 2021, the national average salary was released. Have you reached the standard?
Do you know all four common cache modes?
Where does brain hole come from? New research from the University of California: creative people's neural connections will "take shortcuts"
[tpm2.0 principle and Application guide] Chapter 9, 10 and 11
二叉树的基本概念和性质
Will domestic software testing be biased
Big Ben (Lua)
【塔望方法论】塔望3W消费战略 - U&A研究法