HNUOJ_10089
来源:互联网 发布:专门做软件的网站 编辑:程序博客网 时间:2024/06/06 13:16
CornfieldsTime Limit: 2000ms, Special Time Limit:5000ms,Memory Limit:32768KBTotal submit users: 265, Accepted users:229Problem 10089 : No special judgementProblem descriptionFJ 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 cornfield on the flattest piece of land he can find.
FJ has, at great expense, surveyed his square farm of N x N hectares (1 <= N <= 250). Each hectare has an integer elevation (0 <= elevation <= 250) associated with it.
FJ will present your program with the elevations and a set of K (1 <= K <= 100,000) queries of the form "in this B x B submatrix, what is the maximum and minimum elevation?". The integer B (1 <= B <= N) is the size of one edge of the square cornfield and is a constant for every inquiry. Help FJ find the best place to put his cornfield.
Input* Line 1: Three space-separated integers: N, B, and K.
* Lines 2..N+1: Each line contains N space-separated integers. Line 2 represents row 1; line 3 represents row 2, etc. The first integer on each line represents column 1; the second integer represents column 2; etc.
* Lines N+2..N+K+1: Each line contains two space-separated integers representing a query. The first integer is the top row of the query; the second integer is the left column of the query. The integers are in the range 1..N-B+1.
Output* Lines 1..K: A single integer per line representing the difference between the max and the min in each query.
Sample Input
Problem SourceUSACO
FJ has, at great expense, surveyed his square farm of N x N hectares (1 <= N <= 250). Each hectare has an integer elevation (0 <= elevation <= 250) associated with it.
FJ will present your program with the elevations and a set of K (1 <= K <= 100,000) queries of the form "in this B x B submatrix, what is the maximum and minimum elevation?". The integer B (1 <= B <= N) is the size of one edge of the square cornfield and is a constant for every inquiry. Help FJ find the best place to put his cornfield.
Input* Line 1: Three space-separated integers: N, B, and K.
* Lines 2..N+1: Each line contains N space-separated integers. Line 2 represents row 1; line 3 represents row 2, etc. The first integer on each line represents column 1; the second integer represents column 2; etc.
* Lines N+2..N+K+1: Each line contains two space-separated integers representing a query. The first integer is the top row of the query; the second integer is the left column of the query. The integers are in the range 1..N-B+1.
Output* Lines 1..K: A single integer per line representing the difference between the max and the min in each query.
Sample Input
5 3 15 1 2 6 31 3 5 2 77 2 4 6 19 9 8 6 50 6 9 3 91 2Sample Output
5Judge TipsDynamic Programming
Problem SourceUSACO
本来这道题应该用动态规划来解答
但显然
有一个更加直接简便的方法
#include<stdio.h>#define maxN 250int f[maxN][maxN];int main(){int N,B,K;int i,j;int x,y,X,Y; //int t1-0,t2=250; scanf("%d%d%d",&N,&B,&K);for(i=1;i<=N;i++){for(j=1;j<=N;j++){scanf("%d",&f[i][j]);}}while(K--){scanf("%d%d",&x,&y);X=x+B-1;Y=y+B-1;int t1=0,t2=250;for(i=x;i<=X;i++){for(j=y;j<=Y;j++){if(f[i][j]>t1) { t1=f[i][j]; }if(f[i][j]<t2) { t2=f[i][j]; }}}printf("%d\n",t1-t2); }return 0;}
0 0
- HNUOJ_10089
- L0、L1与L2范数
- 409_用数据库缓存数据
- GIT工作中遇到的问题记录
- 分别使用Python和Java抓取百度搜索结果
- c++定义常量
- HNUOJ_10089
- warehouse management (WM) 学习笔记(一)概述
- Jquery easyui tree的使用
- python基础知识之整除、取余、幂运算
- class 与 struct的区别
- 对CNN中pooling的理解
- 嵌入式系统
- READING NOTE: Aggregated Residual Transformations for Deep Neural Networks
- (a,b)=1 ax+by x>0 y>0的最大不能表示数