• ural1126 Magnetic Storms


    Magnetic Storms

    Time limit: 0.5 second
    Memory limit: 64 MB
    The directory of our kindergarten decided to be attentive to the children's health and not to let them walk outdoors during magnetic storms. Special devices that measure and display magnetic intensity were ordered. If the readout exceeded some certain level the children were told to go indoors. They disliked it because they couldn't play their games up to the end. The nannies hated it because they had to dress and undress children many times.
    After a while it became clear that one could try to forecast magnetic intensity because long periods of quietude alternated with short periods of plenty of sharp peaks (this is called a magnetic storm). Hence a new modification of the devices was ordered.
    The new devices were to remember the situation within several last hours and to display the maximal intensity during the period. If the intensity was low within the last 6 hours the magnetic field was regarded to be quiet; the children were let outdoors and played all the prescript time. Otherwise new peaks were probable and the children spent their time indoors.
    Your task is to write a program for a new version of the device. As a matter of fact you are to solve just the main problem of modification. All the rest is already done.
    You are given a number M which is length of a period (in seconds) within which peaks are to be stored and displayed. A sequence of measured magnetic intensity values is given to you as well. Each measurement is a number within the range from 0 to 100000.
    Your are to output a sequence of values displayed by the device. The first number of the sequence is the maximal element of the first M input numbers, the second number is the maximal element of the 2nd, …, M+1-st input numbers and so on.
    We hope that the new devices with your program won't go back on nannies and children will not walk during magnetic storms.

    Input

    The first line contains a number M, 2 ≤ M ≤ 14000. Then values (N integers) measured by the device follow each one in its line. There is a number −1 in the end. M ≤ N ≤ 25000.

    Output

    a sequence of readouts, each one in its line.

    Sample

    inputoutput
    3
    10
    11
    10
    0
    0
    0
    1
    2
    3
    2
    -1
    
    11
    11
    10
    0
    1
    2
    3
    3
    

    分析:可以水过;

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #define rep(i,m,n) for(i=m;i<=n;i++)
    #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define vi vector<int>
    #define pii pair<int,int>
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define ll long long
    #define pi acos(-1.0)
    const int maxn=1e5+10;
    const int dis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
    using namespace std;
    ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
    ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
    int n,m,k,t,a[maxn],coco[maxn];
    priority_queue<int>p;
    int main()
    {
        int i,j;
        scanf("%d",&n);
        while(scanf("%d",&a[m++])&&a[m-1]!=-1);
        m--;
        for(int i=0;i<=m-n;i++)printf("%d
    ",*max_element(a+i,a+i+n));
        //system("pause");
        return 0;
    }
  • 相关阅读:
    3-4: 一元多项式的乘法与加法运算
    设计模式一装饰者模式
    设计模式一组合模式
    设计模式一命令模式
    设计模式一建造者模式
    设计模式一桥接模式
    设计模式一适配器模式
    设计模式一抽象工厂模式
    排序算法一二分排序
    排序算法一希尔排序
  • 原文地址:https://www.cnblogs.com/dyzll/p/5784924.html
Copyright © 2020-2023  润新知