Ural 1097. Square Country 2

1097. Square Country 2

Time limit: 1.0 second
Memory limit: 64 MB
The Square Parliament of the Square country (recall the corresponding problem from the USU 2001 personal contest) has decreed that the National Square Park be created. Of course, the Park should occupy a large square. Unfortunately, at the moment a lot of square citizens have invested (with the help of last championship's participants) their quadrics into the land so that a part of the country is already occupied. It is now impossible to find a land for the Park without affecting interests of the private owners. Thus some of the pieces of land must be expropriated.
To avoid social unrest the Parliament has to locate the Park so that the interests of as less important as possible citizens were affected. It is better to expropriate land from a thousand of simple citizens than from one member of the Parliament or from one bank-owner.
The occupied pieces of land are marked with numbers from 1 to 100 according to importance of the owner. So all free land and pieces of land belonging to honest tax-payers are marked with number 1, the land belonging to members of the Parliament is marked with 98, possessions of great businessmen are marked with 99, and the property of the square President is marked with 100.

Input

The first line contains the number  L, which is the length of a side of the Square country (in meters), and the number  A, which is the length of a side of the Park (1 ≤  A ≤  L ≤ 10000). The next line contains the number  M (1 ≤  M ≤ 100) of occupied pieces of land (according to the square rules a piece of land is a square with integer coordinates of corners and its sides are parallel to the axes).
The next  M lines contain information about these pieces of land: importance of the owner, length of the square's side and the coordinates of the lower left corner, which are integers from 1 to  L (the coordinates of the lower left corner of the Square country itself are 1,1). Each piece of land is contained in the country and may intersect another piece of land only along its boundary.
Note that land marked with number 1 (that is of importance 1) is not mentioned in the list altogether. Besides, some pieces of land belong to the members of (not square) Jury who helped to formulate the previous problem. This land is marked with number 255 and cannot be expropriated at all.

Output

You should output the least possible importance of land which must be expropriated (a number from 1 to 100) or the word IMPOSSIBLE if it is impossible to create the Park not involving land of importance more than 100. The number and area of expropriated pieces of land are not important. You should only take into account importance of the most important of the affected land-owners.

Sample

input output
5 3
6
94 2 4 1
3 1 1 1
2 1 1 2
2 2 2 1
100 1 2 4
255 1 5 5
3
Problem Author: Stanislav Vasilyev
Problem Source: USU Open Collegiate Programming Contest March'2001 Senior Session
正方形国家的国会决定建立国家公园。当然,此公园必须占用很大的一块正方形地区。
不幸的是,在此时已有很多的公民投资到他们的土地上,以至国家的一些部分
被占有了。现在要找到公园的用地并且不影响那些私人的土地拥有者已经不可能。因此一些土地将被征收。
为了避免社会的不安,国会必须找出公园的用地使影响最低。
如当前是边长为ans,坐标在ansx,ansy,则枚举每个>ans的正方形,设其左上角为x1,y1,右下角为x2,y2,则如果ansx在[x1-ans+1,x2]或者ansy[y1-ans+1,y2]之间,则不可行
#include <stdio.h>
#include <iostream>
using namespace std;
struct record
{
    int x,y,val,l;
};
record a[105];

int main()
{
    int l,m,n,i,j,k,x,y,p,q,now,minn;
    cin>>l>>m>>n;
    for(i=1; i<=n; i++)
        cin>>a[i].val>>a[i].l>>a[i].x>>a[i].y;
    a[0].val=256;
    a[0].l=1;
    a[0].x=0;
    a[0].y=0;
    minn=0x7fffffff;
    for(i=0; i<=n; i++)
        for(j=0; j<=n; j++)
        {
            p=a[i].x+a[i].l;
            q=a[j].y+a[j].l;
            if(p+m-1>l) continue;
            if(q+m-1>l) continue;
            now=1;
            for(k=1; k<=n; k++)
                if((a[k].val>now)&&(p>=a[k].x-m+1)&&(p<=a[k].x+a[k].l-1)&&(q>=a[k].y-m+1)&&(q<=a[k].y+a[k].l-1))
                    now=a[k].val;
            if(now<minn)
                minn=now;
        }
    if(minn<=100)
        cout<<minn<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值