题目大意:给你一个矩形,从(0,0)到(n-1,m-1),然后对其中的某块区域进行操作,操作定义如下:
1.先找到这片区域中的最大值max(初始值为0)
2.把这片区域均赋值为max+h
题目思路:各种纠结。。好笨的说=。=,看了看感觉dp的感觉,但是一点思路没有= =,于是YY线段树,感觉二维,不过不会。。,然后就是正解= =
O(c^2)算法,找到与当前矩形相交的最大值,然后把这个矩形类存下来就行了。。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 1100;
struct MM{
int x1,y1,x2,y2,h;
}M[maxn];
bool jiao(MM a,MM b){
if(a.x1 > b.x2||b.x1 > a.x2||a.y1 > b.y2||b.y1 > a.y2)return false;
else return true;
}
bool vis[maxn];
int main(){
int n,m,c;
while(cin>>n>>m>>c){
for(int i = 0;i < c;i ++){
int a,b,h,x,y;
cin>>a>>b>>h>>x>>y;
M[i] = (MM){x,y,x+a-1,y+b-1,h};
int tmp = 0;
for(int j = 0;j < i;j ++){
if(jiao(M[i],M[j])||jiao(M[j],M[i])){
tmp = max(tmp,M[j].h);
}
}
M[i].h += tmp;
}
int ans = 0;
for(int i = 0;i < c;i ++)ans = max(ans,M[i].h);
cout<<ans<<endl;
}
return 0;
}