一共才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. 用sql语句生成 数据字典

    SELECT 表名=case when a.colorder=1 then d.name else '' end, 表说明=case when a.colorder=1 then isnull(f.v ...

  2. Careercup - Google面试题 - 6253551042953216

    2014-05-06 01:49 题目链接 原题: Modify the following code to add a row number for each line is printed pub ...

  3. jquery JSON的解析方式

    第一次用JSON作为jquery异步请求的传输对象,结果在jquery请求后返回的结果是字符串还是json对象上折腾了半天.等到问题解决了,也大致明白怎么个意思了,归根结底还是对jquery对相关js ...

  4. hdu 3061 Battle 最大权闭合图

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3061 由于小白同学近期习武十分刻苦,很快被晋升为天策军的统帅.而他上任的第一天,就面对了一场极其困难的 ...

  5. NYOJ-73 比大小 AC 分类: NYOJ 2014-01-17 21:29 195人阅读 评论(0) 收藏

    典型的大数题目,这只是大数的比较,到时还有大数加减乘除,更加还有乘方,对于大数,一般用数组或者字符串,因为其他的结构类型一般都没有那么大 的范围!! 这道题目需要你仔细回想怎么比较俩个数字的大小,考虑 ...

  6. 虚拟目录里面的webconfig不继承网站的设置

    必須在上一层虚拟目录(如根目录,上级网站)所在的Web.config加上 如:<location path="." allowOverride="false&quo ...

  7. 在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static

    在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static ! 在C语言中,我们使用pthread_create ...

  8. 快速、直接的XSS漏洞检测爬虫 – XSScrapy

    XSScrapy是一个快速.直接的XSS漏洞检测爬虫,你只需要一个URL,它便可以帮助你发现XSS跨站脚本漏洞. XSScrapy的XSS漏洞攻击测试向量将会覆盖 Http头中的Referer字段 U ...

  9. CSS 类名的单词连字符:下划线还是连接符?

    本文的部分内容整理自我对此问题的解答: 命名 CSS 的类或 ID 时单词间如何连接? - 知乎 问题 CSS 类或 ID 命名时单词间连接通常有这几种写法: 驼峰式: solutionTitle.s ...

  10. c#实现Socket网络编程

    命名空间: 在网络环境下,我们最感兴趣的两个命名空间是System.Net和 System.Net.Sockets. System.Net命名空间通常与较高程的操作有关,例如download或uplo ...