UVa 1312 Cricket Field (枚举+离散化)
题意:在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 (枚举+离散化)的更多相关文章
- UVA 1312 Cricket Field
题意: 在w*h的坐标上给n个点, 然后求一个最大的矩形,使得这个矩形内(不包括边界)没有点,注意边界上是可以有点的. 分析: 把坐标离散化.通过两重循环求矩形的高,然后枚举,看是否能找到对应的矩形. ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
- E - Cricket Field
Description Once upon a time there was a greedy King who ordered his chief Architect to build a fi ...
- 【uva 1312】Cricket Field(算法效率--技巧枚举)
题意:一个 L*R 的网格里有 N 棵树,要求找一个最大空正方形并输出其左下角坐标和长.(1≤L,R≤10000, 0≤N≤100) 解法:枚举空正方形也就是枚举空矩阵,先要固定一个边,才好继续操作. ...
- UVA-1312 Cricket Field (技巧枚举)
题目大意:在一个w*h的网格中,有n个点,找出一个最大的正方形,使得正方形内部没有点. 题目分析:寻找正方形实质上等同于寻找矩形(只需令长宽同取较短的边长).那么枚举出所有可能的长宽组合取最优答案即可 ...
- 紫书 习题8-19 UVa 1312 (枚举技巧)
这道题参考了https://www.cnblogs.com/20143605--pcx/p/4889518.html 这道题就是枚举矩形的宽, 然后从宽再来枚举高. 具体是这样的, 先把所有点的高度已 ...
- UVa 221城市正视图(离散化)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 10465 Homer Simpson (枚举)
10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- UVA 221 - Urban Elevations(离散化)!!!!!!
题意:给出一张俯视图.给出N个建筑物的左下标,长度,宽度,高度.现在求,从南面看,能看到那些建筑? Sample Input 14 160 0 30 60 30 125 0 32 28 60 95 0 ...
随机推荐
- jquery 连写注释;siblings() 方法;jQuery 的3种滑动方法;slideUp()向上滑动;slideDown()向下滑动;slideToggle()来回滑动
首先我们看两个连写注释 第一个: /* 点击头像,显示基本资料 */ $(".f-chatTit a.avatar").click(function(){ $(this).hi ...
- android 自定义组件-带图片的textView
1. 定义属性 <?xml version="1.0" encoding="utf-8"?> <resources> <decla ...
- mysql 数据库常用命令总结
(1)查看数据库可以支持的存储引擎 命令:show engines; (2)查看表结构命令:desc table_name:(3)显示表的创建语句 show create table ta ...
- Ensemble Learning 之 Adaboost
Boosting Boosting 是一种提升方法,将一系列弱学习器组合成为强学习器.基于样本权重的 Boosting 的工作流程是这样的,给定初始训练集构建一个基学习器,根据基学习器对训练样本的分布 ...
- mysql 查看所有存储过程
转载地址:http://zhuixue.iteye.com/blog/375353 查询数据库中的存储过程 方法一: select `name` from mysql.proc where db = ...
- 什么是 db time
AWR中有 DB time这个术语,那么什么是DB time呢? Oracle10gR2 官方文档 给出了详细解释(Oracle10gPerformance Tuning Guide 5.1.1.2 ...
- ios ble 参考
About Core Bluetooth https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Con ...
- Linux系统性能诊断工具纲要
Linux的性能分析工具众多,在微博上发现了系统性能专家Brendan D. Gregg,在最近LinuxCon NA 2014大会上发布的关于Linux性能方面的talk和幻灯片.和去年比较,今年增 ...
- C# 类的多态、结构、接口、抽象、虚函数总结
多态: 类的多态是通过在子类(派生类)中重载基类的虚方法或成员函数来实现的. 可见,重载和虚函数的重写,并在调用时用父类装箱子类对象,是实现多态的一种重要的编程方式. 接口: 接口是一种用来定义程序的 ...
- Android 所有版本区别总结(转)
Android 1.0 第一版商用操作系统 Android 1.1 更新了部分API,新增一些功能,修正了一些错误,同时增加com.google.android.maps包 Android 1.5 智 ...