HDU 5443 The Water Problem (水题,暴力)
题意:给定 n 个数,然后有 q 个询问,问你每个区间的最大值。
析:数据很小,直接暴力即可,不会超时,也可以用RMQ算法。
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn];
int main(){
int T;
cin >> T;
while(T--){
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
scanf("%d", &m);
while(m--){
int l, r;
scanf("%d %d", &l, &r);
int ans = -1;
for(int i = l; i <= r; ++i)
ans = max(ans, a[i]);
printf("%d\n", ans);
}
}
return 0;
}
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int d[maxn][20]; void rmq_init(){
for(int j = 1; (1<<j) <= n; ++j)
for(int i = 1; i + (1<<j) - 1 <= n; ++i)
d[i][j] = max(d[i][j-1], d[i+(1<<(j-1))][j-1]);
} int rmq_query(int l, int r){
//int k = log(r-l+1)/log(2.0);
int k = 0;
while((1<<(k+1)) <= r-l+1) ++k;
return max(d[l][k], d[r-(1<<k)+1][k]);
} int main(){
int T; cin >> T;
while(T--){
scanf("%d", &n);
memset(d, 0, sizeof(d));
for(int i = 0; i < n; ++i)
scanf("%d", &d[i+1][0]);
rmq_init();
scanf("%d", &m);
while(m--){
int l, r;
scanf("%d %d", &l, &r);
printf("%d\n", rmq_query(l, r));
}
}
return 0;
}
HDU 5443 The Water Problem (水题,暴力)的更多相关文章
- 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(长春网络赛——暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java ...
- hdu 5443 The Water Problem
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Description In Land waterless, ...
- HDU 5443 The Water Problem (ST算法)
题目链接:HDU 5443 Problem Description In Land waterless, water is a very limited resource. People always ...
- hdu 5443 The Water Problem 线段树
The Water Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu-5867 Water problem(水题)
题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 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 ...
- 【线段树】HDU 5443 The Water Problem
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 题目大意: T组数据.n个值,m个询问,求区间l到r里的最大值.(n,m<=1000) ...
- HDU 5832 A water problem(某水题)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
随机推荐
- sql DROP 和DELETE、TRUNCATE用法
DROP:删除数据库已存在的表DROP TABLE tbname DELETE:删除记录delete from tbname truncate:清空表,重置索引truncate table tbnam ...
- windows 勾子简介
近段时间因朋友催促让试着写一个监控系统,主要是用来管理孩子使用电脑,帮助孩子合理使用电脑.在网上查询了相关内容发现没有这方面的资料,所以只有自已来试试,要用到钩子来对windows应用程序进行监控,也 ...
- urlrewrite 地址重写
环境: Maven 3.0.4 Urlrewrite 2.5.2 Myeclipse 8.6.1 借此机会顺便提一下 Maven Project 的创建,会了的朋友或还不想了解 Maven 的朋友,可 ...
- DelegatingFilterProxy
安全过滤器链 Spring Security的web架构是完全基于标准的servlet过滤器的. 它没有在内部使用servlet或任何其他基于servlet的框架(比如spring mvc), 所以它 ...
- Google Code Pretiffy 代码 着色 高亮 开源 javascript(JS)库
1.简介 introduction Google Code Pretiffy 是 Google 的一个用来对代码进行语法着色的 JavaScript 库,支持 C/C++, Java, Python, ...
- 【Python】logging模块学习笔记
因为做接口自动化测试遇到的一个代码逻辑上的问题,又不知道具体问题出在哪里,所以在模块化代码之前,先学习下python的日志模块logging. 入门1 入门2 日志级别大小关系为:CRITICAL & ...
- Spring 事务配置5种方式
Spring配置文件中关于事务配置总是由三个组成部分,分别是DataSource.TransactionManager和代理机制这三部分,无论哪种配置方式,一般变化的只是代理机制这部分. DataSo ...
- Java中ThreadLocal的深入理解
官方对ThreadLocal的描述: "该类提供了线程局部(thread-local)变量.这些变量不同于它们的普通对应物,因为访问某个变量(通过其get或set方法)的每个线程都有自己的局 ...
- org-mode
org-mode 编辑 目录 1简介 2扩展 1简介编辑 Org-模式(Org-mode)是文本编辑软件Emacs的一种支持内容分级显示的编辑模式.这种模式支持写 to-do 列表,日志管 ...
- Android数据库升级,数据不丢失解决方案
假设要更新TableC表,建议的做法是: 1) 将TableC重命名为TableC_temp SQL语句可以这样写:ALERT TABLE TableC RENAME TO TableC_temp; ...