题意:在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. 配置openerp的开发环境

    给Eclipse安装PyDev插件启用Eclipse————如果前面的步骤都正确无误的话,那么Eclipse就该能够正常启动了.第一次启动会让你选择一个工作空间,按缺省设置,勾选一下不再提醒,就可以了 ...

  2. 详解Android动画之Frame Animation(转)

    在开始实例讲解之前,先引用官方文档中的一段话: Frame动画是一系列图片按照一定的顺序展示的过程,和放电影的机制很相似,我们称为逐帧动画.Frame动画可以被定义在XML文件中,也可以完全编码实现. ...

  3. python练习程序(c100经典例19)

    题目: 一个数如果恰好等于它的因子之和,这个数就称为“完数”.例如6=1+2+3.编程找出1000以内的所有完数. def foo(a): sra=a; lis=[1]; while 1: for i ...

  4. HDFS的基本概念

    转:http://www.cnblogs.com/forfuture1978/archive/2010/03/14/1685351.html

  5. Android Retrofit实现原理分析

    retrofit有几个关键的地方. 1.用户自定义的接口和接口方法.(由动态代理创建对象.) 2.converter转换器.(把response转换为一个具体的对象) 3.注解的使用. 让我们跟随Ap ...

  6. 利用 Ant 和 Eclipse 有效地提高部署工作效率

    读者定位为具有 Java 和 Ant 使用经验的开发人员. 读者可以学习到如何使用 Ant 解决一些多用户开发环境中,根据不同的目标环境编译成不同部署包的问题. 工作场景 现在有一个 web 项目,是 ...

  7. Page 63-64 Exercises 2.3.7 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)

    Use the following method printPrimes() for question a-d below //Find and prints n prime integers pri ...

  8. mybatis源码学习: 动态代理的应用(慢慢改)

    动态代理概述 在学spring的时候知道使用动态代理实现aop,入门的列子:需要计算所有方法的调用时间.可以每个方法开始和结束都获取当前时间咋办呢.类似这样: long current=system. ...

  9. LeetCode Database: Rank Scores

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  10. Swift相关图书推荐

    Swift与Cocoa框架开发 作      者 [澳] 曼宁(Jonathon Manning),巴特菲尔德-艾迪生(Paris Buttfield 出 版 社 人民邮电出版社 出版时间 2015- ...