The Water Problem

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 602    Accepted Submission(s): 485

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 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
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5449 5448 5447 5446 5445
区间求最大值
次裸裸的RMQ,套上模板即过
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
#define N 50005
int dpmin[N][],dpmax[N][];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int i, j, n, m;
scanf("%d",&n);
memset(dpmin,,sizeof(dpmin));
memset(dpmax,,sizeof(dpmax));
for(i=; i<=n; i++)
{
scanf("%d", &dpmin[i][]);
dpmax[i][]=dpmin[i][];
}
int mm=floor(log(1.0*n)/log(2.0));
for(j=; j<=mm; j++)
for(i=; i<=n; i++)
{
if((i+(<<(j-)))<=n)
{
// dpmin[i][j]=min(dpmin[i][j-1], dpmin[i+(1<<(j-1))][j-1]);
dpmax[i][j]=max(dpmax[i][j-], dpmax[i+(<<(j-))][j-]);
}
}
int x, y; scanf("%d",&m);
for(int i=; i<=m; i++)
{
scanf("%d%d", &x, &y);
int mid=floor(log(y*1.0-x+)/log(2.0));
int maxnum=max(dpmax[x][mid], dpmax[y-(<<mid)+][mid]);
// int minnum=min(dpmin[x][mid], dpmin[y-(1<<mid)+1][mid]);
printf("%d\n", maxnum);
}
}
return ;
}

hdu5443 The Water Problem的更多相关文章

  1. HDU 5832 A water problem(某水题)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. hdu5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. hdu 5443 The Water Problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...

  4. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  5. HDU 5832 A water problem

    A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. HDU 5832 A water problem (带坑水题)

    A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...

  7. hdu 5443 The Water Problem 线段树

    The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. HDU-4974 A simple water problem

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 话说是签到题,我也不懂什么是签到题. A simple water problem Time Limit: ...

  9. The Water Problem(排序)

    The Water Problem Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

随机推荐

  1. Java 继承与重写

    1.类的继承 1)继承 父类:所有子类所共有的属性和行为 子类:子类所特有的属性和行为 通过extends关键字来实现类的继承 子类(Sub class)可以继承父类(Super class)的成员变 ...

  2. 融云红包全新升级,让App用户更便捷地用“钱”交流感情!

    随着移动互联网的飞速发展,如何增强社交关系.留住用户的心已成为移动社交化时代各类App持续探索的问题,除了接入即时通讯的能力,众多社交平台开始通过趣味性十足的红包功能为App中的社交场景赋能.当即时通 ...

  3. [uva816]AbbottsRevenge Abbott的复仇(经典迷宫BFS)

    这题思路就普通的BFS加上一个维度朝向,主要是要注意输入,输出,以及细节的处理 #include<cstdio> #include<cstring> #include<q ...

  4. 香港城市大学:全球首创3D打印微型机器人技术 有望作治疗癌症用途

    香港城市大学(香港城大)的研究团队开发出了全球首创以磁力控制的3D打印微型机器人,该微型机器人技术能做到在生物体内精准运载细胞到指定的位置.新研发的微型机器人有望应用在治疗癌症的靶向治疗,并为细胞层面 ...

  5. c++作业:求N的阶乘。

    N的阶乘就是n.(n-1)! 5的阶乘是什么?5*4*3*2*1 #include <iostream> using namespace std; int jiecheng(int num ...

  6. Return Largest Numbers in Arrays-freecodecamp算法题目

    Return Largest Numbers in Arrays(找出多个数组中的最大数) 要求 大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 思路 用 ...

  7. Android深度探索总结

    Android深度探索前四章总结 通过这几章的学习真实体会到“移植”的概念:为特定设备定制Android的过程,但是移植的过程中开发最多的就是支持各种硬件设备的Linux驱动程序,本章对Android ...

  8. c++ 函数指针应用,定义一个方法,传入两个参数和一个函数指针,并返回结果

    #include <iostream> #include <string> using namespace std; double add(double x, double y ...

  9. 自然数的拆分(DFS)

    题目描述: 任何一个大于1的自然数n,总可以拆分成若干个小于n的自然数之和. 输入格式: 待拆分的自然数n. 输出格式: 若干数的加法式子. 样例输入: 7 样例输出: 1+1+1+1+1+1+1 1 ...

  10. 洛谷 2023 [AHOI2009]维护序列

    洛谷 2023 [AHOI2009]维护序列 洛谷原题传送门 这个题也是一道经典的线段树模版(其实洛谷的模版二改一下输入顺序就能AC),其中包括区间乘法修改.区间加法修改.区间查询三个操作. 线段树的 ...