标签:des style blog http color os strong io
Description
Input
Output
Sample Input
5 3 1 5 1 2 6 3 1 3 5 2 7 7 2 4 6 1 9 9 8 6 5 0 6 9 3 9 1 2
Sample Output
5
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <math.h> 5 #include <algorithm> 6 using namespace std; 7 unsigned char dpi[300][300][9],dpa[300][300][9]; 8 int main() 9 { 10 int n,b,k; 11 int i,j,ii,jj,x,y; 12 unsigned char maxa,mina; 13 scanf("%d%d%d",&n,&b,&k); 14 memset(dpi,0,sizeof(dpi)); 15 memset(dpa,0,sizeof(dpa)); 16 for(i=0; i<n; i++) 17 for(j=0; j<n; j++) 18 scanf("%d",&x),dpa[i][j][0]=x,dpi[i][j][0]=dpa[i][j][0]; 19 for(ii=1; ii<9; ii++) 20 { 21 for(i=0; i+(1<<ii) - 1 <n; i++) 22 { 23 for(j=0; j+(1<<ii)-1<n; j++) 24 { 25 dpi[i][j][ii]=min(dpi[i][j][ii-1],dpi[i+(1<<(ii-1))][j][ii-1]); 26 dpi[i][j][ii]=min(dpi[i][j][ii],dpi[i][j+(1<<(ii-1))][ii-1]); 27 dpi[i][j][ii]=min(dpi[i][j][ii],dpi[i+(1<<(ii-1))][j+(1<<(ii-1))][ii-1]); 28 dpa[i][j][ii]=max(dpa[i][j][ii-1],dpa[i+(1<<(ii-1))][j][ii-1]); 29 dpa[i][j][ii]=max(dpa[i][j][ii],dpa[i][j+(1<<(ii-1))][ii-1]); 30 dpa[i][j][ii]=max(dpa[i][j][ii],dpa[i+(1<<(ii-1))][j+(1<<(ii-1))][ii-1]); 31 } 32 } 33 } 34 int kk=log(1.0*b)/log(2.0); 35 for(i=0; i<k; i++) 36 { 37 scanf("%d%d",&x,&y); 38 x--,y--; 39 maxa=dpa[x][y][kk]; 40 maxa=max(maxa,dpa[x][y+b-(1<<kk)][kk]); 41 maxa=max(maxa,dpa[x+b-(1<<kk)][y][kk]); 42 maxa=max(maxa,dpa[x+b-(1<<kk)][y+b-(1<<kk)][kk]); 43 44 mina=dpi[x][y][kk]; 45 mina=min(mina,dpi[x][y+b-(1<<kk)][kk]); 46 mina=min(mina,dpi[x+b-(1<<kk)][y][kk]); 47 mina=min(mina,dpi[x+b-(1<<kk)][y+b-(1<<kk)][kk]); 48 printf("%d\n",maxa-mina); 49 } 50 }
Cornfields poj2019 二维RMQ,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ERKE/p/3876815.html