当前位置:网站首页>[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 ~
边栏推荐
猜你喜欢
随机推荐
按照功能对Boost库进行分类
Significance and measures of security encryption of industrial control equipment
2022熔化焊接与热切割上岗证题目模拟考试平台操作
新版图解网络PDF即将发布
AirServer2022最新版功能介绍及下载
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
杰理之、产线装配环节【篇】
中通笔试题:翻转字符串,例如abcd打印出dcba
测试撤销1
【级联分类器训练参数】Training Haar Cascades
【Opencv450】HOG+SVM 与Hog+cascade进行行人检测
杰理之关于长按开机检测抬起问题【篇】
leetcode刷题:二叉树03(二叉树的后序遍历)
杰理之蓝牙耳机品控和生产技巧【篇】
leetcode刷题:栈与队列02(用队列实现栈)
Slf4j打印异常的堆栈信息
2022安全员-A证考题及在线模拟考试
Test cancellation 1
在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
leetcode刷题:栈与队列05(逆波兰表达式求值)