POJ 2019 Cornfields (RMQ?反正我暴力了)

【题意简述】:题目告诉我们很多数据,有N,表示这个农场的大小N*N,还有B,表示我们要测量的那个小正方形的大小B*B,还有K,代表我们要在这个N*N的农场上测几组数据。要测量的那个小正方形的左上角的坐标给你了,x和y。现在让我们求出在这个B*B的小正方形中最大的数值减去最小的数值结果是多少

【分析】:这本应是个二维的RMQ问题:

http://blog.csdn.net/u013749862/article/details/39008855

下面是别人用RMQ的解法:

http://kmplayer.iteye.com/blog/575725

接下来是我恶心 暴力的代码:

// 368K  891Ms  险过!!
// 应该是用二维的RMQ,但是,暴力也过了
#include<iostream>
#include<cstdio>
using namespace std;

int farm[251][251];
#define Max 251
#define Min 0

int N,B,K;
int x,y;

int main()
{
	scanf("%d%d%d",&N,&B,&K);
	for(int i= 1 ;i<=N;i++)
	{
		for(int j =1;j<=N;j++)
		{
			scanf("%d",&farm[i][j]);
		}
	}
	while(K--)
	{

	scanf("%d%d",&x,&y);
	int max1 = Min;
	int min1 = Max;
	for(int i = x;i<x+B;i++)
	{
		for(int j = y;j<y+B;j++)
		{
			if(farm[i][j]>max1)
				max1 = farm[i][j];
			if(farm[i][j]<min1)
				min1 = farm[i][j];
		}
	}
	printf("%d\n",max1 - min1);
	}
	return 0;
}
时间: 2024-08-29 03:50:42

POJ 2019 Cornfields (RMQ?反正我暴力了)的相关文章

POJ 2019 Cornfields 二维RMQ

题目来源:POJ 2019 Cornfields 题意:求正方形二维区间最大最小值的差 思路:直接二维ST搞 试模版而已 #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn = 255; int dp[maxn][maxn][8][8]; int dp2[maxn][maxn][8][8]; int a[maxn][maxn]; int n

RMQ [POJ 2019] Cornfields

Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5516   Accepted: 2714 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfie

POJ 2019 Cornfields

相比以前的RMQ不同的是,这是一个二维的ST算法 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define N 300 int minbest[8][8][N][N]; int maxbest[8][8][N][N]; ///int lg[N]; int getmax(int a,int b,int c,int d) {

POJ 2019 Cornfields 二维线段树的初始化与最值查询

模板到不行.. 连更新都没有.. .存个模板. 理解留到小结的时候再写. #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <queue> #include <cmath> #include <stack> #include <map> #

POJ训练计划1035_Spell checker(串处理/暴力)

3.算法综合实践--搜索引擎 上网搜索有关"搜索引擎"的相关资料,包括但不限于以下方面(至少要有2个方面):搜索引擎岗位要求.搜索引擎工作原理.搜索引 擎涉及到教材中哪些算法.搜索引擎的盈利模式.搜索引擎源码链接.国内外搜索引擎公司现状等. <1>搜索引擎指自动从因特网搜集信息,经过一定整理以后,提供给用户进行查询的系统.因特网上的信息浩瀚万千,而且毫无秩序,所有的信息像汪洋上的一个个小岛,网页链接是这些小岛之间纵横交错的桥梁,而搜索引擎,则为用户绘制一幅一目了然的信息地图

poj Problem A. Score Sequence(暴力)

这道题,对于我这种英文不好的人来说,有点费劲啊. 题目的意思:给你两组成绩,你要找出他们之间最大的公共子序列,不能有重复,然后输出两组数据. 第一组就是:按照从大到小输出最大子序列. 第二组就是:按照个位数由小到大输出,若个位数一样大,则小的在前输出最大子序列. 解题思路基本上已经出来了,就是千万要注意就是在最长子序列匹配之前就就把重复的数字给删除. 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h

POJ训练计划3080_Blue Jeans(串处理/暴力)

Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11542   Accepted: 4962 Description The Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousa

poj 3264(模板RMQ)

Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34488   Accepted: 16203 Case Time Limit: 2000MS Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer Joh

poj 3368(RMQ简单应用)

Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13317   Accepted: 4894 Description You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you are given several queries cons