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 ...
随机推荐
- POJ 3211 Washing Clothes【01背包】
题意:给出n种颜色,m件衣服,再分别给出m件衣服的颜色,和洗所需要的时间,dearboy和他的妹子一起洗衣服,且同种颜色的衣服不能同时洗,也不能两个人同时洗一件衣服,问洗完这m件衣服至少需要的时间 先 ...
- 使用Phalcon开发工具碰到的数据库问题"Table 'XXX' doesn't exist in database when dumping meta-data for XXX"
使用Phalcon开发工具,通过命令行生成程序框架 设置好config.php,在对数据库进行读取.保存数据的时候出现了问题“Table 'XXX' doesn't exist in database ...
- 部署在IIS服务器的asp.net 网站,禁止访问指定类型文件
网站上的一些文件不希望用户访问,可以通过下面的方式简单实现.不需写代码(在IIS6下试验过). 第一步,在IIS中实现映射. 哪些文件需要特殊处理. 通俗的将就是将哪种类型的文件交给特定的工厂来处理. ...
- a标签包input引起的问题
最近公司中的一个项目中,有一个同事跟我说,他写的输入框不能选中输入内容了,并且光标也不能插入到已写好的文字其他位置. 简化了一下他的代码结构,如下: <a href="javascri ...
- Intent七大属性
一.Intent的作用是什么? 1.Intent 用于封装程序的”调用意图“.两个Activity之间,可以把需要交换的数据封装成Bundle对象,然后使用Intent携带Bundle对象,实现 ...
- uglifyjs使用
1.安装Nodejs:去这里下载并安装. 2.打开cmd,运行npm,node应该会有输出东西 3.如果在window上运行Node.js的npm报Error: ENOENT, stat 'C:\Us ...
- 虚拟机VMware tools作用以及其安装
虚拟机VMware tools的作用(1). 更新虚拟机中的显卡驱动, 使虚拟机中的XWindows可以运行在SVGA模式下.在客户操作系统中安装Mware Tools非常重要.如果不安装VMware ...
- [Everyday Mathematics]20150301
设 $f(x)$ 在 $[-1,1]$ 上有任意阶导数, $f^{(n)}(0)=0$, 其中 $n$ 是任意正整数, 且存在 $C>0$, $$\bex |f^{(n)}(x)|\leq C^ ...
- ylb:SQL Server中的escape(逃逸)
ylbtech-SQL Server:SQL Server-SQL中的escape(逃逸) SQL Server中的escape(逃逸). 1,SQL Server中的escape(逃逸) 返回顶部 ...
- 【LeetCode】120 - Triangle
原题:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacen ...