题意:http://www.nocow.cn/index.php/Translate:URAL/1097
离散化之后找最大没有被覆盖的正方形。暴力能过。
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#define LL long long
#define DB double
#define SI(a) scanf("%d",&a)
#define SD(a) scanf("%lf",&a)
#define SS(a) scanf("%s",a)
#define SF scanf
#define PF printf
#define MM(a,v) memset(a,v,sizeof(a))
#define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REPD(i,a,b) for(int (i)=(a);(i)>(b);(i)--)
#define N 209
#define INF 0x3f3f3f3f
#define EPS 1e-8
#define bug puts("bug")
using namespace std;
int v[N][N];
int x[N],y[N];
int n,m;
int k;
int lx=0,ly=0;
struct R{
int val,x,y,l;
void get(){
SI(val);SI(l);SI(x);SI(y);
}
} re[N],tmp[N];
int finx(int t)
{
int l = 0,r = lx-1,mid;
while(l<=r)
{
mid = (l+r)>>1;
if(x[mid]==t) return mid;
if(x[mid]>t) r = mid-1;
else l = mid+1;
}
return -1;
}
int finy(int t)
{
int l = 0,r = ly-1,mid;
while(l<=r)
{
mid = (l+r)>>1;
if(y[mid]==t) return mid;
if(y[mid]>t) r = mid-1;
else l = mid+1;
}
return -1;
}
int oor(int a,int b)
{
for(int i=a;x[i]-x[a]<m;i++)
for(int j=b;y[j]-y[b]<m;j++)
if(v[i][j]) return 0;
return 1;
}
int ok(int c)
{
MM(v,0);
REP(i,0,k)
if(re[i].val>c)
{
int xl = finx(re[i].x),xr = finx(re[i].x+re[i].l);
int yl = finy(re[i].y),yr = finy(re[i].y+re[i].l);
REP(_i,xl,xr)
REP(_j,yl,yr)
v[_i][_j] = 1;
}
REP(i,0,lx)
{
if(x[i]+m>n+1) break;
REP(j,0,ly)
{
if(y[j]+m>n+1) break;
if(oor(i,j)) return 1;
}
}
return 0;
}
void solve()
{
x[lx++] = 1;y[ly++] = 1;
x[lx++] = n+1;y[ly++] = n+1;
REP(i,0,k)
{
x[lx++] = re[i].x;
x[lx++] = re[i].x+re[i].l;
y[ly++] = re[i].y;
y[ly++] = re[i].y+re[i].l;
}
sort(x,x+lx);sort(y,y+ly);
lx = unique(x,x+lx)-x;
ly = unique(y,y+ly)-y;
x[lx] = y[ly] = INF;
int ans=-1,l=1,r=100;
while(l<=r)
{
int mid = (l+r)>>1;
if(ok(mid))
{
ans = mid;
r = mid-1;
}else
{
l = mid+1;
}
}
if(ans==-1) puts("IMPOSSIBLE");
else PF("%d\n",ans);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
SI(n);SI(m);
SI(k);
REP(i,0,k)
{
re[i].get();
}
solve();
return 0;
}