题意:在w*h的图上有n个点,要求找出一个正方形面积最大,且没有点落在该正方形内部。

析:枚举所有的y坐标,去查找最大矩形,不断更新。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map> using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e4 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct node{
int x, y;
bool operator < (const node &p) const{
return x < p.x || (x == p.x && y < p.y);
}
};
int d[maxn];
node a[maxn];
int t, x; void solve(){
int ans = 0, ansx, ansy;
for(int i = 0; i < x; ++i){
for(int j = i+1; j < x; ++j){
int maxy = d[j], miny = d[i];
int h = maxy - miny, w = 0, tmp = 0;
for(int k = 0; k < t; ++k){
if(a[k].y <= miny || a[k].y >= maxy) continue;
w = a[k].x - tmp;
if(ans < min(w, h)){
ans = min(w, h);
ansx = tmp; ansy = miny;
}
tmp = a[k].x;
} w = m - tmp;
if(ans < min(w, h)){
ans = min(w, h);
ansx = tmp; ansy = miny;
}
}
}
printf("%d %d %d\n", ansx, ansy, ans);
} int main(){
int T; cin >> T;
while(T--){
scanf("%d %d %d", &t, &m, &n);
for(int i = 0; i < t; ++i){ scanf("%d %d", &a[i].x, &a[i].y); d[i+1] = a[i].y; }
d[0] = 0; d[t+1] = n;
sort(d, d+t+2);
sort(a, a+t);
x = unique(d, d+t+2) - d;
solve();
if(T) printf("\n");
}
return 0;
}

UVa 1312 Cricket Field (枚举+离散化)的更多相关文章

  1. UVA 1312 Cricket Field

    题意: 在w*h的坐标上给n个点, 然后求一个最大的矩形,使得这个矩形内(不包括边界)没有点,注意边界上是可以有点的. 分析: 把坐标离散化.通过两重循环求矩形的高,然后枚举,看是否能找到对应的矩形. ...

  2. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  3. E - Cricket Field

    Description   Once upon a time there was a greedy King who ordered his chief Architect to build a fi ...

  4. 【uva 1312】Cricket Field(算法效率--技巧枚举)

    题意:一个 L*R 的网格里有 N 棵树,要求找一个最大空正方形并输出其左下角坐标和长.(1≤L,R≤10000, 0≤N≤100) 解法:枚举空正方形也就是枚举空矩阵,先要固定一个边,才好继续操作. ...

  5. UVA-1312 Cricket Field (技巧枚举)

    题目大意:在一个w*h的网格中,有n个点,找出一个最大的正方形,使得正方形内部没有点. 题目分析:寻找正方形实质上等同于寻找矩形(只需令长宽同取较短的边长).那么枚举出所有可能的长宽组合取最优答案即可 ...

  6. 紫书 习题8-19 UVa 1312 (枚举技巧)

    这道题参考了https://www.cnblogs.com/20143605--pcx/p/4889518.html 这道题就是枚举矩形的宽, 然后从宽再来枚举高. 具体是这样的, 先把所有点的高度已 ...

  7. UVa 221城市正视图(离散化)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVa 10465 Homer Simpson (枚举)

    10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  9. UVA 221 - Urban Elevations(离散化)!!!!!!

    题意:给出一张俯视图.给出N个建筑物的左下标,长度,宽度,高度.现在求,从南面看,能看到那些建筑? Sample Input 14 160 0 30 60 30 125 0 32 28 60 95 0 ...

随机推荐

  1. POJ 3628 Bookshelf 2【01背包】

    题意:给出n头牛的身高,以及一个书架的高度,问怎样选取牛,使得它们的高的和超过书架的高度最小. 将背包容量转化为所有牛的身高之和,就可以用01背包来做=== #include<iostream& ...

  2. IE 火狐浏览器对时间格式的兼容性;使用原型对象的方式 prototype关键字;时间格式化

    在ie中 时间格式如果用横杠来显示  "2013-05-10 19:20:59" 是可以正确识别的(如果用斜杠,IE也可以正确识别), 但是如果是火狐,则只能识别斜杠模式 &quo ...

  3. [转载] FFmpeg API 变更记录

    最近一两年内FFmpeg项目发展的速度很快,本来是一件好事.但是随之而来的问题就是其API(接口函数)一直在发生变动.这么一来基于旧一点版本的FFmpeg的程序的代码在最新的类库上可能就跑不通了. 例 ...

  4. Filling a Path 模式

    Filling a Path When you fill the current path, Quartz acts as if each subpath contained in the path ...

  5. OpenVz一键安装openvpn

    # !/bin/sh # OPENVPN SERVER CONFIGURATION echo "####################################" echo ...

  6. myeclipse安装

    http://www.cnol.cc/2013/1427.html(我用这个) http://www.myeclipseide.cn/windows.html http://download.csdn ...

  7. 实现两个N*N矩阵的乘法,矩阵由一维数组表示

    实现两个N*N矩阵的乘法,矩阵由一维数组表示. 先介绍一下矩阵的加法: void Add(int rows, int cols) { ;i<rows;i++) { ;j<cols;j++) ...

  8. Delphi 关闭MDI子窗口

    需要在子窗口的onClose事件中吧Action = caFree; 就可以了. procedure Tfrm_aa.FormClose(Sender: TObject; var Action: TC ...

  9. 【转】CentOS 6.3 X64自动安装OpenERP 7.0脚本

    原文地址:OpenERP 7.0安装与配置 #!/bin/bash -e # Modified script from Carlos E. Fonseca Zorrilla # . Add the t ...

  10. Oracle中本行记录和上一行记录进行比较lead over 函数处理

    遇到问题:多表关联查询,有一个要求是,同一保单号,对应多个投资产品Code.以及投资比例,每一个保单号有一个总的投资金额.要求同一保单号那一行,只有第一个总金额有值,剩下的code对应的总金额置空. ...