当前位置:网站首页>[noip2013] building block competition [noip2018] road laying greed / difference
[noip2013] building block competition [noip2018] road laying greed / difference
2022-07-01 21:45:00 【Xuanji, you have no heart】
In fact, these two questions are the same idea , A positive change , One changes in reverse . So you can traverse the array from front to back , If a[i] > a[i - 1], Just add the difference between them , If a[i] <= a[i - 1],a[i] Can use a[i - 1] To achieve , That is, there is no need to come out more times alone 【 greedy 】. If you look at the difference , That is, the answer is the sum of all positive numbers in the difference array .
Building blocks competition
Original link : Sign in — major IT Written interview preparation platform _ Cattle from
AC Code :
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
#define PII pair<int,int>
#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define rrep(i, n) for(int i = n; i >= 1; ++i)
using namespace std;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
int a[N], b[N];
int main()
{
int n;
scanf("%d", &n);
int res = 0;
rep(i, n) scanf("%d", &a[i]), b[i] = a[i] - a[i - 1];
for(int i = 1; i <= n; i++)
if(a[i] > a[i - 1]) res += a[i] - a[i - 1];
cout << res;
return 0;
}
Road laying
Sign in — major IT Written interview preparation platform _ Cattle from
AC Code :
The same way of thinking , You can write it yourself ~
边栏推荐
猜你喜欢
图片拼图微信小程序源码_支持多模板制作和流量主
BC35&BC95 ONENET MQTT(旧)
朋友圈社区程序源码分享
MIT|256KB 内存下的设备上训练
【深度学习】利用深度学习监控女朋友的微信聊天?
杰理之、产线装配环节【篇】
leetcode刷题:栈与队列02(用队列实现栈)
【Opencv450】HOG+SVM 与Hog+cascade进行行人检测
Talking from mlperf: how to lead the next wave of AI accelerator
Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
随机推荐
测试撤销1
PMP与NPDP之间的区别是什么?
MySQL数据库驱动(JDBC Driver)jar包下载
收藏:存储知识全面总结
leetcode刷题:栈与队列01(用栈实现队列)
NIO与传统IO的区别
一次调试去了解redis集群的slot机制
都能看懂的LIS(最长上升子序列)问题[通俗易懂]
K-means based user portrait clustering model
tensorflow 张量做卷积,输入量与卷积核维度的理解
Manually implement function isinstanceof (child, parent)
中通笔试题:翻转字符串,例如abcd打印出dcba
MySQL清空表数据
JS how to get a list of elements in a collection object
手动实现function isInstanceOf(child,Parent)
Accelera Systems Initiative是一个独立的非营利组织
浏览器tab页之间的通信
2022年低压电工考试试题及答案
Fundamentals - IO intensive computing and CPU intensive computing
杰理之、产线装配环节【篇】