ural1097 Square Country 2

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

分析:参考http://blog.csdn.net/jyysc2010/article/details/9968813;

   暴力枚举矩形顶点即可,复杂度o(M3);

   不过感觉数据略有问题;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e2+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t,b[maxn],c[maxn],ans,p,q;
struct node
{
    int id,x,y,z;
    node(){}
    node(int _id,int _z,int _x,int _y)
    {
        id=_id,x=_x,y=_y,z=_z;
    }
}a[maxn];
int main()
{
    int i,j;
    ans=1000;
    scanf("%d%d%d",&n,&m,&k);
    rep(i,1,k)
    {
        int b,c,d,e;
        scanf("%d%d%d%d",&b,&c,&d,&e);
        a[i]=node(b,c,d,e);
    }
    a[0]=node(0,1,0,0);
    rep(i,0,k)rep(j,0,k)
    {
        int x=a[i].x+a[i].z,y=a[j].y+a[j].z,now=1;
        if(x+m-1>n||y+m-1>n)continue;
        rep(t,1,k)
        {
            if(a[t].x>x+m-1||a[t].y>y+m-1||a[t].x+a[t].z-1<x||a[t].y+a[t].z-1<y)continue;
            now=max(now,a[t].id);
        }
        ans=min(ans,now);
    }
    if(ans<=100)printf("%d\n",ans);
    else puts("IMPOSSIBLE");
    //system("Pause");
    return 0;
}
时间: 2024-12-25 14:32:12

ural1097 Square Country 2的相关文章

ural 1073. Square Country

1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament has passed a law about a land. According to the law each citizen of th

URAL 1073 Square Country(DP)

题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 :其实就是求x12+x22+--+Xn2中的最小的n. 1 //1073 2 #include <stdio.h> 3 #include <iostream> 4 #include <math.h> 5 6 using namespace std ; 7 8 int a[

ural 1073. Square Country 完全背包

点击打开链接 1073. Square Country Time limit: 1.0 second Memory limit: 64 MB There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament has passed a law about a land. According to the law each citiz

URAL1073——DP——Square Country

Description There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament has passed a law about a land. According to the law each citizen of the country has a right to buy land. A land is sold i

URAL 1073 Square Country(DP)

Square Country 大意: 买一块边长为 a 的正方形地需要的钱数是 a^2, 现在输入N为钱的数目,求最少购买地的块数可以凑够N. 思路:DP,由背包思想推出来的dp[i] = min(dp[i], dp[j-i*i]+1);  方块都是由正方形组成的,所以是i*i,循环的时候也是i*i. #include <stdio.h> #define min(a, b) ((a) > (b) ? (b) :(a)) int n; int dp[60005]; int main() {

01背包 URAL 1073 Square Country

题目传送门 1 /* 2 题意:问n最少能是几个数的平方和 3 01背包:j*j的土地买不买的问题 4 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2200721.html 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cmath> 9 #include <cstring> 10 using namespace std;

Ural 1073 Square Country (DP)

题目地址:Ural 1073 DP水题.也可以说是背包. #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include

URAL 1698. Square Country 5(记忆化搜索)

题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质:以他为后几位的两个数相乘,乘积的后几位仍是这个自守数.刚好n位的自守数一定是两个,当然1位的时候0和1是没有算进去的,但是题目中1是要加上的,所以从第0位深搜枚举到第n位.还有另一种方法,因为一个数是自守数当且仅当这个数是另一个自守数的后缀,2000位的自守数只有两个,所以存下来直接数也行 1 #

【算法】将正整数表示为平方数之和

问题来源 Timus Online Judge 网站上有这么一道题目:1073. Square Country.这道题目的输入是一个不大于 60,000 的正整数,要求计算出该正整数最少能够使用多少个正整数的平方和来表示.这道题目的时间限制是 1 秒. 问题解答 <数论导引(第5版)>([英]G.H.Hardy.E.M.Wright 著,人民邮电出版社,2008年10月第1版)第 320 页有以下定理: 定理 369(Lagrange 定理): 每个正整数都是四个平方数之和 在这个定理中,平方