zoukankan      html  css  js  c++  java
  • Codeforces Round #109 (Div. 2) A. I_love_%username%【打擂台算法/满足当前数字在已经出现的数字的最大值和最小值之间的个数】

    A. I_love_%username%
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.

    One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).

    Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictlymore points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.

    Input

    The first line contains the single integer n (1 ≤ n ≤ 1000) — the number of contests where the coder participated.

    The next line contains n space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.

    Output

    Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.

    Examples
    input
    5
    100 50 200 150 200
    output
    2
    input
    10
    4664 6496 5814 7010 5762 5736 6944 4850 3698 7242
    output
    4
    Note

    In the first sample the performances number 2 and 3 are amazing.

    In the second sample the performances number 2, 4, 9 and 10 are amazing.

     【分析】:一串数字,求满足当前数字在已经出现的数字的最大值和最小值之间的个数(严格大于和小于)遍历一次,维护当前的最大值和最小值,然后判断计数就行了。

    【代码】:

    #include <bits/stdc++.h>
    
    using namespace std;
    int n,a[1050],sum,maxx,minx;
    int main()
    {
        while(cin>>n)
        {
            sum=0;
            cin>>a[0];//!!!
            minx=maxx=a[0];
            for(int i=1;i<n;i++)
            {
                cin>>a[i];
                if(a[i]>maxx)
                {
                    sum++;
                    maxx=a[i];
                }
                if(a[i]<minx)
                {
                    sum++;
                    minx=a[i];
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }
    数组开大点!
  • 相关阅读:
    玉蓉方面膜加盟费多少 玉蓉方绿豆面膜怎么做代理 怎么加盟玉蓉方
    音频处理软件:GoldWave,太强大了,批量处理音频
    杂记 SY
    ThinkPHP函数详解--D函数:实例化数据模型类
    杂记
    如何选择jQuery版本 1.x? 2.x? 3.x?
    传值涉及到中文字符串时,字符编码的问题
    对数字进行分组处理:每10个为一组
    mac下安装protocol buffer并用python解析
    淘宝返利攻略
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7941286.html
Copyright © 2011-2022 走看看