ZOJ3578(Matrix)

Matrix

Time Limit: 10 Seconds      Memory Limit: 131072 KB

N*M coordinate plane ((0, 0)~(n, m)). Initially the value of all N*M grids are 0.
An operation T(a, b, h, x, y) is defined as follow:
1. Select the maximum value in the matrix (x, y) ~ (x+a, y+b), suppose the maximum value is max
2. Change all the value in the matrix (x, y) ~ (x+a, y+b) into max+h
After C operations, please output the maximum value in the whole N*M coordinate.

Input

The input consists of several cases. 
For each case, the first line consists of three positive integers N , M and C (N ≤ 1000, M ≤ 1000, C ≤ 1000). In the following C lines, each line consists of 5 non-negative number, aibihixiyi (0 ≤ hi ≤ 10000, 0 ≤ xi < n, 0 ≤ yi < m).

Output

For each case, output the maximum height.

Sample Input

3 2 2
2 1 9 1 1
1 1 2 2 1

Sample Output

11

  感受:判断两个矩阵是否相交,考虑一定不相交的情况。若考虑相交条件则是有可能相交。并且呀,不相交对立面不一定是相交啊(好人的对立面不一定是坏人啊,有可能是不好不坏的人啦,世界并不是由二元性组成的呀!)

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 #include<algorithm>
 5 using namespace std;
 6 struct Matrix
 7 {
 8   int x1,x2,y1,y2,maxn;
 9 };
10 Matrix matrix [1000+5];
11 bool cover(Matrix a,Matrix b)
12 {
13     if(a.x1>=b.x2||b.x1>=a.x2) return false;
14     if(a.y1>=b.y2||b.y1>=a.y2) return false;
15     return true;
16 }
17 int n,m,c;
18 int x,y,h,a,b;
19 int main()
20 {
21     while(~scanf("%d%d%d",&n,&m,&c))
22     {
23         int ans=0;
24 
25         memset(matrix,0,sizeof(matrix));
26         for(int i=0;i<c;i++)
27         {
28             int temp=0;
29             scanf("%d%d%d%d%d",&a,&b,&h,&x,&y);
30             matrix[i].x1=x;
31             matrix[i].x2=x+a;
32             matrix[i].y1=y;
33             matrix[i].y2=y+b;
34             //matrix[i].h=h;
35             for(int j=0;j<i;j++)
36             {
37                 if(cover(matrix[i],matrix[j]))
38                     temp=max(temp,matrix[j].maxn);
39             }
40             matrix[i].maxn=temp+h;
41             ans=max(ans,matrix[i].maxn);
42         }
43         printf("%d\n",ans);
44     }
45 
46 
47     return 0;
48 }
49 
50 //1 2
51 //1
52 //1 5

 

posted @ 2015-07-31 11:00  JoneZP  阅读(144)  评论(0编辑  收藏  举报