hdu5443 The Water Problem
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
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.
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
2
3
4
4
5
1
999999
999999
1
#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的更多相关文章
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- hdu5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- HDU 5867 Water problem (模拟)
Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...
- HDU 5832 A water problem
A water problem Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU-4974 A simple water problem
http://acm.hdu.edu.cn/showproblem.php?pid=4974 话说是签到题,我也不懂什么是签到题. A simple water problem Time Limit: ...
- The Water Problem(排序)
The Water Problem Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
随机推荐
- 在linux命令行下如何访问网址
1. wget Ubuntu系统自带,会将访问的首页下载到本地 admin@iZj6c9c6vaqj1i0a9j7h78Z:~$ wget www.baidu.com --2019-04-20 17: ...
- Understanding NFS Caching
Understanding NFS Caching Filesystem caching is a great tool for improving performance, but it is im ...
- tomcat - CPU高占用问题记录
先查询进程 top 再根据进程号,查出进程的线程 ps p 3036 -L -o pcpu,pid,tid,time,tname,cmd 得到最高使用率CPU的线程TID,转换成16进制 printf ...
- java基础——接口与抽象类的区别
(1)首先接口和抽象类的设计目的就是不一样的.接口是对动作的抽象,而抽象类是对根源的抽象. (2)对于抽象类,一个类只能继承一个抽象类.但是一个类可以同时实现多个接口. (3)接口是公开的,里面不能有 ...
- cocos2d-x中的字符串操作
1:循环体中字符串的构造. 通常用于多个有规律的文件的名字,诸如:[NSString stringWithFormat:@"filed.png",i].我们可以通过spr ...
- virtualvenv+django+uWSGI+nginx 部署
原创博文 转载请注明出处! 1. virtualvenv 2. django 3. uWSGI 4. nginx 5. 踩坑记录 1. virtualvenv virtualvenv install ...
- scipy学习之(二)——io操作及其misc操作对图片的处理
SciPy有许多模块.类和函数,io子模块可用于从各种文件格式中读取数据和将数据写入各种文件格式. from scipy import io import numpy as np 生成数据 data ...
- Django项目SECRET_KEY等敏感信息保存
在我们做完django项目后,向生产环境部署时,为了避免一些敏感信息被有心人利用,我们应该将其保护起来,比如说在settings配置中的一些密码等内容存在操作系统内,通过调用来使用,比如下面这种做法: ...
- 【MySql】Mysql ERROR 1067: Invalid default value for ‘date’ 解决
在给一个表添加字段的时候,忽然发现会报一个date类型的字段的默认值错误,郁闷~ 经过排查,原来是MySQL的配置问题,在wamp下,MySQL 5.7里是没有设置 SQL_MODE 的. 1.my. ...
- 标准C++(3)重载
一.函数的重载 c++中同一作用域下能够定义同名的函数(这就叫重载),但必须满足如下要求: 1.函数的参数列表必须不同,可以使参数数量不同,也可以使参数的类型不同,甚至是参数的顺序不同. 2.函数的返 ...