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源码中的Javascript基础知识(四)— jQuery.fn.init方法
$() 即调用了jQuery.fn.init方法 jQuery = function( selector, context ) { return new jQuery.fn.init( selecto ...
- 阿里云linux服务器安装Phalcon-----"phalcon Volt directory can't be written" "gcc: internal compiler error: Killed (program cc1)"
这里特别蛋疼的一件事是官方英文文档和中文文档命令参数略有不同 中文文档: //通用平台下安装指定的软件包: sudo yum install git gcc make pcre-devel php-d ...
- phpstorm10.0.1和webstorm11注册
webstorm11 for win 注册时选择“License server”输入“http://15.idea.lanyus.com/”点击“OK” phpstorm10.0.1 for win ...
- android事件系列-onTouch事件与手势操作
提示记忆:应用流程:在Activity中对控件执行 view.setOnTouchListener( OnTouchListener i);实现里面的OnTouchListener 接口中的方法,重点 ...
- matlab数据的导入和导出,以matlab工作区workspace为source和destination
MATLAB支持工作区的保存.用户可以将工作区或工作区中的变量以文件的形式保存,以备在需要时再次导入. 保存工作区可以通过菜单进行,也可以通过命令窗口进行. 数据导出 1. 保存整个工作区 选择Fil ...
- struts2自定义声明校验器
1 //新建一个validators.xml在src根资源下,会覆盖default.xml的validators,所以你懂得 //接着,若使用声明式校验,则要把配置文件xxxAction-valida ...
- 深入学习Heritrix---解析处理器(Processor)(转)
深入学习Heritrix---解析处理器(Processor) 本节解析与处理器有关的内容. 与处理器有关的主要在以下几个类:Processor(处理器类),ProcessorChain(处理器类), ...
- delphi TeeChart保存3种图片文件
var vForm: Tfrm_ChemaShowMainChild;begin vForm := GetActiveForm; vForm.cht_Edit.SaveToMetafile('C:\1 ...
- .NET下用C#实现邮箱激活功能
最近要用到安全邮箱激活的功能,故写篇博客记录下. 思路:在表中增加一个字段State来记录邮箱是否激活(0激活,1未激活.) 1.发送邮件. 1-1,给邮箱发送邮件.内容:激活地址+GUID. ...
- 白盒测试之初识gtest工具
因为公司最近对软件产品质量提高了要求,之前项目组中黑盒测试方法就越来越无法满足公司的要求.虽然作为研发,但是也要求对白盒测试有一个系统的了解(毕竟之前没有系统的接触过白盒测试). 单元测试工具有很多种 ...