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. 在linux命令行下如何访问网址

    1. wget Ubuntu系统自带,会将访问的首页下载到本地 admin@iZj6c9c6vaqj1i0a9j7h78Z:~$ wget www.baidu.com --2019-04-20 17: ...

  2. Understanding NFS Caching

    Understanding NFS Caching Filesystem caching is a great tool for improving performance, but it is im ...

  3. tomcat - CPU高占用问题记录

    先查询进程 top 再根据进程号,查出进程的线程 ps p 3036 -L -o pcpu,pid,tid,time,tname,cmd 得到最高使用率CPU的线程TID,转换成16进制 printf ...

  4. java基础——接口与抽象类的区别

    (1)首先接口和抽象类的设计目的就是不一样的.接口是对动作的抽象,而抽象类是对根源的抽象. (2)对于抽象类,一个类只能继承一个抽象类.但是一个类可以同时实现多个接口. (3)接口是公开的,里面不能有 ...

  5. cocos2d-x中的字符串操作

    1:循环体中字符串的构造.      通常用于多个有规律的文件的名字,诸如:[NSString stringWithFormat:@"filed.png",i].我们可以通过spr ...

  6. virtualvenv+django+uWSGI+nginx 部署

    原创博文 转载请注明出处! 1. virtualvenv 2. django 3. uWSGI 4. nginx 5. 踩坑记录 1. virtualvenv virtualvenv install ...

  7. scipy学习之(二)——io操作及其misc操作对图片的处理

    SciPy有许多模块.类和函数,io子模块可用于从各种文件格式中读取数据和将数据写入各种文件格式. from scipy import io import numpy as np 生成数据 data ...

  8. Django项目SECRET_KEY等敏感信息保存

    在我们做完django项目后,向生产环境部署时,为了避免一些敏感信息被有心人利用,我们应该将其保护起来,比如说在settings配置中的一些密码等内容存在操作系统内,通过调用来使用,比如下面这种做法: ...

  9. 【MySql】Mysql ERROR 1067: Invalid default value for ‘date’ 解决

    在给一个表添加字段的时候,忽然发现会报一个date类型的字段的默认值错误,郁闷~ 经过排查,原来是MySQL的配置问题,在wamp下,MySQL 5.7里是没有设置 SQL_MODE 的. 1.my. ...

  10. 标准C++(3)重载

    一.函数的重载 c++中同一作用域下能够定义同名的函数(这就叫重载),但必须满足如下要求: 1.函数的参数列表必须不同,可以使参数数量不同,也可以使参数的类型不同,甚至是参数的顺序不同. 2.函数的返 ...