hdu 5443 The Water Problem(长春网络赛——暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443

The Water Problem

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1084    Accepted Submission(s): 863

Problem Description

In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,anrepresenting
the size of the water source. Given a set of queries each containing 2 integers l and r,
please find out the biggest water source between al and ar.

Input

First you are given an integer T(T≤10) indicating
the number of test cases. For each test case, there is a number n(0≤n≤1000) on
a line representing the number of water sources. n integers
follow, respectively a1,a2,a3,...,an,
and each integer is in {1,...,106}.
On the next line, there is a number q(0≤q≤1000) representing
the number of queries. After that, there will be q lines
with two integers l and r(1≤l≤r≤n) indicating
the range of which you should find out the biggest water source.

Output

For each query, output an integer representing the size of the biggest water source.

Sample Input

3
1
100
1
1 1
5
1 2 3 4 5
5
1 2
1 3
2 4
3 4
3 5
3
1 999999 1
4
1 1
1 2
2 3
3 3

Sample Output

100
2
3
4
4
5
1
999999
999999
1

Source

2015 ACM/ICPC Asia Regional Changchun Online

Recommend

hujie   |   We have carefully selected several similar problems for you:  5664 pid=5663" style="color:rgb(26,92,200); text-decoration:none">5663 5662 5661 5660

题目大意:给出n个水池的水量,找出区间内最大的水量。

求区间最值。正常都採用线段树的方法。可是这题数据量不大。全部暴力就过了~

详见代码。

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int t;
    int a[1010],l,r;
    scanf("%d",&t);
    while (t--)
    {
        int n;
        scanf("%d",&n);
        for (int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
        }
        int q;
        scanf("%d",&q);
        while (q--)
        {
            int Max=0;
            scanf("%d%d",&l,&r);
            for (int i=l; i<=r; i++)
            {
                if (a[i]>Max)
                    Max=a[i];
            }
            cout<<Max<<endl;
        }
    }
    return 0;
}
时间: 2024-10-12 13:30:20

hdu 5443 The Water Problem(长春网络赛——暴力)的相关文章

hdu 5443 The Water Problem 线段树

The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of wat

HDU 5443 The Water Problem

The Water Problem Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 153    Accepted Submission(s): 123 Problem Description In Land waterless, water is a very limited resource. People always figh

ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)

Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,an representing the size of the water source. Given a set of queries eac

Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)

题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最后问a[i]==n(i最大)时候,i最后一次出现的下标是多少? 解题思路: 问题可以转化为求a[i] == n (i最大),数列前i项的和为多少. index: 1 2 3 4 5 6 7 8 9 10 a:        1 2 2 3 3 4 4 4 5 5 可以观察出:ans[1] = 1,

HDU 5443 The Water Problem (水题,暴力)

题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值. 析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue

hdu4271 Find Black Hand 2012长春网络赛E题 最短编辑距离

hdu4271 Find Black Hand  2012长春网络赛E题  最短编辑距离 Find Black Hand Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 19   Accepted Submission(s) : 1 Problem Description I like playing game with my friend

HDU 5832 A water problem(某水题)

HDU 5832 A water problem(某水题) Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is

15年-ICPC长春-网络赛

ID name status one word    POJ 5437 Alisha’s Party 赛后AC. 优先队列,模拟.对时间t排序 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <queue> using namespace std; struct Node { char name[210]; int v

HDU 5832 A water problem(取模~)—— 2016中国大学生程序设计竞赛 - 网络选拔赛

传送门 A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 60    Accepted Submission(s): 37 Problem Description Two planets named Haha and Xixi in the universe and they were created wit