URAL 1097 Square Country 2 离散化
一共才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 离散化的更多相关文章
- 01背包 URAL 1073 Square Country
题目传送门 /* 题意:问n最少能是几个数的平方和 01背包:j*j的土地买不买的问题 详细解释:http://www.cnblogs.com/vongang/archive/2011/10/07/2 ...
- ural 1073. Square Country
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...
- ural 1698. Square Country 5(记忆化搜索)
1698. Square Country 5 Time limit: 2.0 secondMemory limit: 64 MB The first arithmetical operation ta ...
- ural 1073.Square Country(动态规划)
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...
- Ural 1073 Square Country (DP)
题目地址:Ural 1073 DP水题.也能够说是背包. #include <iostream> #include <cstdio> #include <string&g ...
- URAL 1073 Square Country(DP)
题目链接 题意 :这个人要投资地,每块地都是正方形并且边长都是整数,他希望他要买的地尽量的少碎块.每买一块地要付的钱是边长的平方,而且会得到一个一份证书,给你一个钱数,让你求出能得到的证书个数. 思路 ...
- URAL 1698. Square Country 5(记忆化搜索)
题目链接 题意 : 自守数的定义:如果某个数的平方的末尾几位数等于这个数,那么就称这个数为自守数.例如5*5=25,则5就是自守数.让你求不超过n位的自守数有多少 思路 : 实际上,自守数还有两个性质 ...
- ural1097 Square Country 2
Square Country 2 Time limit: 1.0 secondMemory limit: 64 MB The Square Parliament of the Square count ...
- Timus Online Judge:ural:1006. Square Frames
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1006 看到题第一反应:这玩意怎么读入…… 本地的话因为是全角字符,会占两个位置,所以需要 ...
随机推荐
- 典型:Eayui项目aspx页面引用js
<link href="../Scripts/easyui1.3.5/themes/default/easyui.css" rel="stylesheet" ...
- The income statement
The income statement measures performance over some period of time,usually a quarter or a year.The ...
- 【CentOs】sudo使用
在使用Linux系统过程中,通常情况下,我们都会使用普通用户进行日常操作,而root用户只有在权限分配及系统设置时才会使用,而root用户的密码也不可能公开.普通用户执行到系统程序时,需要临时提升权限 ...
- jQuery的弹出窗口插件colorbox
官方网站:http://colorpowered.com/colorbox/ 支持 照片,照片组,幻灯片,ajax,内联 和 iframe 框架. 通过CSS 控制外观,使用用户可以很容易重新定制外观 ...
- poj 1986 Distance Queries LCA
题目链接:http://poj.org/problem?id=1986 Farmer John's cows refused to run in his marathon since he chose ...
- Leetcode#68 Text Justification
原题地址 没有复杂的算法,纯粹的模拟题 先试探,计算出一行能放几个单词 然后计算出单词之间有几个空格,注意,如果空格总长度无法整除空格数,前面的空格长度通通+1 最后放单词.放空格,组成一行,加入结果 ...
- java数组与内存控制
1.1数组的初始化 数组是大多数编程语言都提供一种的复合结构,如果程序需要多个类型相同的变量时,就可以考虑定义一个数组.java语言的数组变量时引用类型的变量,因此具有java独有的特性. java数 ...
- PE文件之资源讲解
资源是PE文件中非常重要的部分,几乎所有的PE文件中都包含资源,与导入表与导出表相比,资源的组织方式要复杂得多,要了解资源的话,重点在于了解资源整体上的组织结构. 我们知道,PE文件资源中的内容包括: ...
- [Js/Jquery]天气接口简单使用
写在前面 今天在群里有朋友使用一个天气api,觉得挺实用的,就记录一下.省的以后再花费功夫去找. 地址:http://www.k780.com/api,在这个网站提供了实用的几种接口,比如查询ip,天 ...
- 如何理解JS项目
JS API(DOM/PhoneGap/Cordova/NodeJS/Library/Android/MongoDB....)最基础,可以看懂一行代码. -------> JS OOP, JS语 ...