HDU 5443-找区间最大值

来源:互联网 发布:php数组键不为数字 编辑:程序博客网 时间:2024/06/06 07:26

题意:

暴力找区间最大值


输入:

3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 22 33 3

输出:

1002344519999999999991

代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn=1005;int a[maxn];int n,q,l,r;int main (){    int T;    scanf("%d",&T);    while(T--)    {        scanf("%d",&n);        for(int i=1; i<=n; i++)            scanf("%d",&a[i]);        scanf("%d",&q);        int tmp;        while(q--)        {            tmp=0;            scanf("%d%d",&l,&r);            for (int i=l; i<=r; i++)                tmp=max(tmp, a[i]);            cout<<tmp<<endl;        }    }    return 0;}


0 0
原创粉丝点击