一共才100个正方形,将所有正方形左下角和右上角的X坐标和Y坐标离散化,直接枚举新建公园的点的坐标即可。

O(n^3)的时间复杂度。

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; const int MAXN = ;
const int INF = ; struct Land
{
int x, y;
int len;
int import;
}; int N, K, M;
int cnt;
Land land[MAXN];
int cntX, cntY;
int X[ MAXN << ];
int Y[ MAXN << ]; bool InPark( Land park, Land d )
{
int stx = park.x, sty = park.y;
int edx = park.x + park.len, edy = park.y + park.len; //printf("%d %d %d %d\n", stx, sty, edx, edy );
//printf("%d %d %d %d\n---\n", d.x, d.y, d.x + d.len, d.y + d.len ); if ( d.x >= stx && d.x < edx )
{
if ( d.y >= sty && d.y < edy ) return true;
if ( d.y + d.len > sty && d.y + d.len <= edy ) return true;
} if ( d.x + d.len > stx && d.x + d.len <= edx )
{
if ( d.y >= sty && d.y < edy ) return true;
if ( d.y + d.len > sty && d.y + d.len <= edy ) return true;
}
return false;
} void solved()
{
int ans = INF;
for( int i = ; i < cntX; ++i )
for( int j = ; j < cntY; ++j )
{
Land park;
park.x = X[i], park.y = Y[j];
park.len = K; if ( park.x + park.len <= + N && park.y + park.len <= + N )
{
int influence = ;
for ( int k = ; k < M; ++k )
{
if ( InPark( park, land[k] ) )
{
//puts("***");
influence = max( influence, land[k].import );
}
}
ans = min( ans, influence );
}
} if ( ans <= ) printf( "%d\n", ans );
else puts("IMPOSSIBLE"); return;
} int main()
{
//freopen( "s.out", "w", stdout );
while ( ~scanf( "%d%d", &N, &K ) )
{
scanf( "%d", &M );
cntX = cntY = ;
for ( int i = ; i < M; ++i )
{
scanf("%d%d%d%d", &land[i].import, &land[i].len, &land[i].x, &land[i].y );
X[cntX++] = land[i].x;
X[cntX++] = land[i].x + land[i].len;
Y[cntY++] = land[i].y;
Y[cntY++] = land[i].y + land[i].len;
} X[cntX++] = ;
X[cntX++] = + N;
Y[cntY++] = ;
Y[cntY++] = + N; sort( X, X + cntX );
sort( Y, Y + cntY );
cntX = unique( X, X + cntX ) - X;
cntY = unique( Y, Y + cntY ) - Y; solved();
}
return ;
}

URAL 1097 Square Country 2 离散化的更多相关文章

  1. 01背包 URAL 1073 Square Country

    题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...

  2. ural 1073. Square Country

    1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...

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

    1698. Square Country 5 Time limit: 2.0 secondMemory limit: 64 MB The first arithmetical operation ta ...

  4. ural 1073.Square Country(动态规划)

    1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...

  5. Ural 1073 Square Country (DP)

    题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...

  6. URAL 1073 Square Country(DP)

    题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 ...

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

    题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...

  8. ural1097 Square Country 2

    Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square count ...

  9. Timus Online Judge:ural:1006. Square Frames

    原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1006 看到题第一反应:这玩意怎么读入…… 本地的话因为是全角字符,会占两个位置,所以需要 ...

随机推荐

  1. 3、颜色的字符串、十进制、十六进制相互转换(color convert between dec、hex and string )

    int color_int=***; 1.(十进制整数)转换成(十六进制的字符串) String color_hex = String.format("#%06X", (0xFFF ...

  2. 【Django】Django命令(Manager.py)

    django-admin.py startproject mysite 该命令在当前目录创建一个 mysite 目录. django-admin.py这个文件在C:\Python27\Lib\site ...

  3. shell编程之环境变量

    在shell编程里我们首先接触到的是环境变量,常用命令说明 1. 使用echo命令查看单个环境变量.例如: echo $PATH 2. 使用env查看所有环境变量.例如: env 3. 使用set查看 ...

  4. 【BZOJ】【2002】【HNOI2010】弹飞绵羊

    呃这题的Hint写着splay启发式合并……但是蒟蒻不懂T_T只好写个简单的LCT来蒙混过关,就是时间效率上差劲的很…… 不过能够一次AC心情也是蛮愉悦的~ /******************** ...

  5. linux 配置ssh免密码登录

    1.确保主机名唯一 主机名修改方法: a.修改/etc/sysconfig/network,HOSTNAME=想要设置的主机名称 b.修改/etc/hosts,127.0.0.1   localhos ...

  6. 跨站点端口攻击 – XSPA(SSPA)

    许多Web应用程序提供的功能将数据从其他Web服务器,由于种种原因.下载XML提要,从远程服务器,Web应用程序可以使用用户指定的URL,获取图像,此功能可能会被滥用,使制作的查询使用易受攻击的Web ...

  7. 游戏引擎网络开发者的 64 做与不做 | Part 1 | 客户端方面

    摘要:纵观过去 10 年的游戏领域,单机向网络发展已成为一个非常大的趋势.然而,为游戏添加网络支持的过程中往往存在着大量挑战,这里将为大家揭示游戏引擎网络开发者的 64 个做与不做. [编者按]时下, ...

  8. POJ 2004 Mix and Build (预处理+dfs)

    题意: 给N个字符串,要求出一个序列,在该序列中,后一个串,是由前一个串加一个字母后得来的(顺序可以改动). 问最多能组成多长的序列.思路:将给的字符串排序,再对所有的字符串按长度从小到大排序,若长度 ...

  9. POJ 2136

    #include <iostream> #include <string> #define MAXN 26 using namespace std; int _m[MAXN]; ...

  10. Activity学习(三)——跳转传值

    Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据.   Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...