zoukankan      html  css  js  c++  java
  • noip2013 积木大赛

    P1969 积木大赛

      • 594通过
      • 1.1K提交
    • 题目提供者该用户不存在
    • 标签模拟2013NOIp提高组
    • 难度普及/提高-

    提交该题 讨论 题解记录

    最新讨论

    题目描述

    春春幼儿园举办了一年一度的“积木大赛”。今年比赛的内容是搭建一座宽度为n的大厦,大厦可以看成由n块宽度为1的积木组成,第i块积木的最终高度需要是hi。

    在搭建开始之前,没有任何积木(可以看成n块高度为 0 的积木)。接下来每次操作,小朋友们可以选择一段连续区间[l, r],然后将第第 L 块到第 R 块之间(含第 L 块和第 R 块)所有积木的高度分别增加1。

    小 M 是个聪明的小朋友,她很快想出了建造大厦的最佳策略,使得建造所需的操作次数最少。但她不是一个勤于动手的孩子,所以想请你帮忙实现这个策略,并求出最少的操作次数。

    输入输出格式

    输入格式:

    输入文件为 block.in

    输入包含两行,第一行包含一个整数n,表示大厦的宽度。

    第二行包含n个整数,第i个整数为hi 。

    输出格式:

    输出文件为 block.out

    仅一行,即建造所需的最少操作数。

    输入输出样例

    输入样例#1:
    5
    2 3 4 1 2
    输出样例#1:
    5

    说明

    【样例解释】

    其中一种可行的最佳方案,依次选择

    [1,5] [1,3] [2,3] [3,3] [5,5]

    【数据范围】

    对于 30%的数据,有1 ≤ n ≤ 10;

    对于 70%的数据,有1 ≤ n ≤ 1000;

    对于 100%的数据,有1 ≤ n ≤ 100000,0 ≤ hi≤ 10000。

    分析:既然要最少的建造步数,很容易能想到一次选择的区间越大,那么步数就最少.关键是怎么确定这个区间的大小,从左往右扫描,如果一个点比左边的点低或高,则称这个点为断点,如果断点比左边的大,那么次数就要加上多的多少,如果比左边的小,那么久不必增加,断点要不断更新.

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    int n,last,now, ans = 0;
    
    int main()
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &now);
            if (now > last)
                ans += now - last;
            last = now;
        }
        printf("%d", ans);
    
        return 0;
    }
  • 相关阅读:
    Blank page instead of the SharePoint Central Administration site
    BizTalk 2010 BAM Configure
    Use ODBA with Visio 2007
    Handling SOAP Exceptions in BizTalk Orchestrations
    BizTalk与WebMethods之间的EDI交换
    Append messages in BizTalk
    FTP protocol commands
    Using Dynamic Maps in BizTalk(From CodeProject)
    Synchronous To Asynchronous Flows Without An Orchestration的简单实现
    WSE3 and "Action for ultimate recipient is required but not present in the message."
  • 原文地址:https://www.cnblogs.com/zbtrs/p/5742634.html
Copyright © 2011-2022 走看看