HDU_2888_Check Corners
2018-06-17 21:48:02来源:未知 阅读 ()
Check Corners
Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3247 Accepted Submission(s): 1173
For each test case, the first line contains two integers m, n (1 <= m, n <= 300), which is the size of the row and column of the matrix, respectively. The next m lines with n integers each gives the elements of the matrix which fit in non-negative 32-bit integer.
The next line contains a single integer Q (1 <= Q <= 1,000,000), the number of queries. The next Q lines give one query on each line, with four integers r1, c1, r2, c2 (1 <= r1 <= r2 <= m, 1 <= c1 <= c2 <= n), which are the indices of the upper-left corner and lower-right corner of the sub-matrix in question.
- 二维区间max,打二维ST表
- dp[i][j][e][f]表明从矩阵左上角(i,j)开始宽度范围是2^e,高度范围是2^f的矩形
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <climits> 7 #include <cmath> 8 #include <vector> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <map> 13 using namespace std; 14 typedef long long LL ; 15 typedef unsigned long long ULL ; 16 const int maxn = 1e5 + 10 ; 17 const int inf = 0x3f3f3f3f ; 18 const int npos = -1 ; 19 const int mod = 1e9 + 7 ; 20 const int mxx = 100 + 5 ; 21 const double eps = 1e-6 ; 22 const double PI = acos(-1.0) ; 23 24 int max4(int a, int b, int c, int d){ 25 return max(max(a,b),max(c,d)); 26 } 27 int m, n, fac[9], dp[310][310][9][9]; 28 int X1, Y1, X2, Y2, ans, mx, q; 29 int main(){ 30 // freopen("in.txt","r",stdin); 31 // freopen("out.txt","w",stdout); 32 for(int i=0;i<9;i++) 33 fac[i]=(1<<i); 34 while(~scanf("%d %d",&m,&n)){ 35 for(int i=1;i<=m;i++) 36 for(int j=1;j<=n;j++) 37 scanf("%d",&dp[i][j][0][0]); 38 int rk=(int)(log((double)m)/log(2.0)); 39 int ck=(int)(log((double)n)/log(2.0)); 40 for(int e=0;e<=rk;e++) 41 for(int f=0;f<=ck;f++) 42 if(e || f) 43 for(int i=1;i+fac[e]-1<=m;i++) 44 for(int j=1;j+fac[f]-1<=n;j++) 45 if(!e) 46 dp[i][j][e][f]=max(dp[i][j][e][f-1],dp[i][j+fac[f-1]][e][f-1]); 47 else if(!f) 48 dp[i][j][e][f]=max(dp[i][j][e-1][f],dp[i+fac[e-1]][j][e-1][f]); 49 else 50 dp[i][j][e][f]=max4(dp[i][j][e-1][f-1],dp[i+fac[e-1]][j][e-1][f-1],dp[i][j+fac[f-1]][e-1][f-1],dp[i+fac[e-1]][j+fac[f-1]][e-1][f-1]); 51 scanf("%d",&q); 52 while(q--){ 53 ans=0; 54 scanf("%d %d %d %d",&X1,&Y1,&X2,&Y2); 55 rk=(int)(log((double)(X2-X1+1))/log(2.0)); 56 ck=(int)(log((double)(Y2-Y1+1))/log(2.0)); 57 mx=max4(dp[X1][Y1][rk][ck],dp[X2-fac[rk]+1][Y1][rk][ck],dp[X1][Y2-fac[ck]+1][rk][ck],dp[X2-fac[rk]+1][Y2-fac[ck]+1][rk][ck]); 58 if(mx==dp[X1][Y1][0][0]|| 59 mx==dp[X1][Y2][0][0]|| 60 mx==dp[X2][Y1][0][0]|| 61 mx==dp[X2][Y2][0][0]){ 62 ans=1; 63 } 64 printf("%d %s\n",mx,ans?"yes":"no"); 65 } 66 } 67 return 0; 68 }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash