• C.Candy


    There are NN children standing in a line. Each child is assigned a rating value.

    You are giving candies to these children subjected to the following requirements:

    (1) Each child must have at least one candy.

    (2) Children with a higher rating get more candies than their neighbors.

    What is the minimum candies you must give?

    Input:

    The input consists of multiple test cases.

    The first line of each test case has a number NN, which indicates the number of students.

    Then there are NN students rating values, 1 leq N leq 300, 1 leq values leq 100001N300,1values10000.

    Output:

    The minimum number of candies you must give.

    样例1

    输入:

    5
    1 2 3 4 5
    5 
    1 3 5 3 6

    输出:

    15
    9

    贪心。调了半天。扫两遍

    /* ***********************************************
    Created Time  :2016/4/24 17:15:25
    File Name     :1.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int a[maxn];
    int b[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int n;
        while(cin>>n){
            for(int i=0;i<n;i++)cin>>a[i];
            int tmp=1;
            cle(b);
            for(int i=1;i<n;i++){
                if(a[i]>a[i-1])b[i]=max(tmp++,b[i]);
                else tmp=1;
            }    
            tmp=1;
            for(int i=n-2;i>=0;i--){
                if(a[i]>a[i+1])b[i]=max(tmp++,b[i]);
                else tmp=1;
            }
            int sum=0;
            for(int i=0;i<=n;i++)sum+=b[i];
            cout<<sum+n<<endl;
        }
        return 0;
    }
  • 相关阅读:
    ODBC数据源选项卡中的系统DNS,用户DNS和文件DNS
    Oracle学习的零散问题
    【今日CV 计算机视觉论文速览】Thu, 7 Mar 2019
    【图像风格转换】项目参考资料总结
    【今日CV 计算机视觉论文速览】Thu, 28 Feb 2019
    【今日CV 计算机视觉论文速览】Tue, 26 Feb 2019
    【今日CV 计算机视觉论文速览】Wed, 27 Feb 2019
    【python】set集合基础与使用
    hdu 4259 Double Dealing
    hdu 1538 A Puzzle for Pirates 博弈论
  • 原文地址:https://www.cnblogs.com/pk28/p/5427537.html
Copyright © 2020-2023  润新知