当前位置:网站首页>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
边栏推荐
- 【剑指 Offer】59 - I. 滑动窗口的最大值
- I feel cheated. Wechat tests the function of "size number" internally, and two wechat can be registered with the same mobile number
- cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
- 初识缓存以及ehcache初体验「建议收藏」
- RISCV64
- ES6笔记一
- RIP和OSPF的区别和配置命令
- 基于图像和激光的多模态点云融合与视觉定位
- CVPR 2022 - learning non target knowledge for semantic segmentation of small samples
- Cadre de validation des données Apache bval réutilisé
猜你喜欢
Save the memory of the model! Meta & UC Berkeley proposed memvit. The modeling time support is 30 times longer than the existing model, and the calculation amount is only increased by 4.5%
【塔望方法论】塔望3W消费战略 - U&A研究法
2022.07.02
Complete e-commerce system
GSAP animation library
标准ACL与扩展ACL
Cadre de validation des données Apache bval réutilisé
博睿数据入选《2022爱分析 · IT运维厂商全景报告》
学习open62541 --- [67] 添加自定义Enum并显示名字
Reinforcement learning - learning notes 8 | Q-learning
随机推荐
国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
LeetCode 497(C#)
2022上半年朋友圈都在传的10本书,找到了
【塔望方法论】塔望3W消费战略 - U&A研究法
Learn open62541 -- [67] add custom enum and display name
A hodgepodge of ICER knowledge points (attached with a large number of topics, which are constantly being updated)
【MIME笔记】
數據驗證框架 Apache BVal 再使用
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
POJ 1182 :食物链(并查集)[通俗易懂]
Hongmeng smart home [1.0]
In 2021, the national average salary was released. Have you reached the standard?
Redis的发布与订阅
ES6笔记一
Embedded interview questions (algorithm part)
Save the memory of the model! Meta & UC Berkeley proposed memvit. The modeling time support is 30 times longer than the existing model, and the calculation amount is only increased by 4.5%
Continuous test (CT) practical experience sharing
How many are there (Lua)
单臂路由和三层交换的简单配置
SQLite SQL exception near "with": syntax error