一共才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. 【Binary Tree Level Order Traversal II 】cpp

    题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...

  2. Oracle 相关概念详解

    一.前言 笔者对于Oracle数据库的理解,很长时间停留在“镜花水月”的状态,你说不懂吧,又会用,一较真起来吧,对一些基本概念又说不出一个道道来~如果想要在编码的路上走得更远,这个必定也是绕不过的坎, ...

  3. Ming Rpc

    原文地址:http://iwantmoon.com/Post/487ab43d609f49d28ff4228241e2b7c7 Rpc(Remote Procedure Call Protocal)远 ...

  4. CentOS 6.5下Git服务器搭建

    1 . Git服务器搭建 1. 环境部署 系统环境:服务器端:CentOS 6.5 ,ip:192.168.56.1 客户端:CentOS 6.5 ,ip:192.168.56.101 软件版本:服务 ...

  5. JS判断用户是否在线的方法

    在以前坐项目的时候,经常碰见通过sessionLisnter来判断用户是否在线的方法,但是由于用户关闭浏览器时不会立刻是否session,因此大部分时候都考虑在页面中通过JS来监控页面是否关闭. 网络 ...

  6. 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  7. shell编程之数组和关联数组

    一.数组类似c语言的数组 1.两种赋值方式 可以整体定义数组:ARRAY_NAME=(value0 value1 value2 value3 ...) 此时数组的下标默认是从0开始的 还可以单独定义数 ...

  8. JSP for query

    1. JSP中部分常用标签: Form.jsp <%@ page contentType="text/html;charset=UTF-8" language="j ...

  9. phonegap上传以及下载图片

    在phonegap中,有时我们需要从服务器下载图片以及上传图片,这个时候可以用到官方提供的一个插件:FileTransfer 首先通过命令添加插件: cordova plugin add org.ap ...

  10. Oracle 时间处理(加减)

    一. 类似SQL SERVER中DateAdd select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate ...