一共才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. 查看Android应用签名信息

    本文档介绍在Android下如何查看自己的应用签名及三方APK或系统APK签名信息,包含其中的MD5.SHA1.SHA256值和签名算法等信息. 1.查看自己的应用签名 可以通过两种方式查看 (1)  ...

  2. 以前用过Extjs技术的开发人员在学习Extjs4时需要注意的问题

            以前学习过Extjs的同学,在学习Extjs4的时候需要注意几个关键改变: 1.Extjs4的新的类系统. 2.Extjs4中MVC思路 3.Extjs4中的新的命名规范(结合新的MV ...

  3. Codeforces Round #274 (Div. 2)

    A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...

  4. wrap device

    刚刚看见了,wrap device && reference device 区别在这里 https://msdn.microsoft.com/en-us/library/windows ...

  5. iOS开发之runtime的运用-获取当前网络状态

    之前写过runtime的一些东西,这次通过runtime获取一些苹果官方不想让你拿到的东西,比如,状态栏内部的控件属性.本文将通过runtime带你一步步拿到状态栏中显示网络状态的控件,然后通过监测该 ...

  6. nodejs快速入门

    目录: 编写第一个Node.js程序: 异步式I/O和事件循环: 模块和包: 调试. 1. 编写第一个Node.js程序: Node.js 具有深厚的开源血统,它诞生于托管了许多优秀开源项目的网站—— ...

  7. 将HTML转成XHTML并清除一些无用的标签和属性

    介绍 这是一个能帮你从HTML生成有效XHTML的经典库.它还提供对标签以及属性过滤的支持.你可以指定允许哪些标签和属性可在出现在输出中,而其他的标签过滤掉.你也可以使用这个库清理Microsoft ...

  8. svg琐碎01

    svg中的<g>主要用来做分组的定位,使用transform="translate(xOffset,yOffset)" 更改起始坐标. transform中的坐标是相对 ...

  9. c3p0 --1

    # # This file is detritus from various testing attempts  # the values below may change, and often do ...

  10. Razor之代码复用

    原文:http://www.cnblogs.com/youring2/archive/2011/07/26/2115493.html 1.布局(Layout)复用 Layout的使用,就像WebFor ...