HDU 5301 Buildings 数学
Buildings
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5301
Description
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be paralled to the building's sides.
The floor is represented in the ground plan as a large rectangle with dimensions n×m, where each apartment is a smaller rectangle with dimensions a×b located inside. For each apartment, its dimensions can be different from each other. The number a and b must be integers.
Additionally, the apartments must completely cover the floor without one 1×1 square located on (x,y). The apartments must not intersect, but they can touch.
For this example, this is a sample of n=2,m=3,x=2,y=2.
To prevent darkness indoors, the apartments must have windows. Therefore, each apartment must share its at least one side with the edge of the rectangle representing the floor so it is possible to place a window.
Your boss XXY wants to minimize the maximum areas of all apartments, now it's your turn to tell him the answer.
Input
There are at most 10000 testcases.
For each testcase, only four space-separated integers, n,m,x,y(1≤n,m≤108,n×m>1,1≤x≤n,1≤y≤m).
Output
For each testcase, print only one interger, representing the answer.
Sample Input
2 3 2 2
3 3 1 1
Sample Output
1
2
Hint
题意
给你一个n*m的土地,然后让你分成若干块,你需要保证这些块至少有一条边靠近土地的边上。
然后这个土地上有一个坏点。
问你这些块的最小面积是多少。
题解:
考虑暴力,显然答案就是其中某一块砖离边界最近距离值的最大值。
然后由于有一个坏点,那么我们就只用分析一下这个坏点附近的四个点就好了。
然后再考虑考虑特殊情况就好了。
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b;
int main()
{
while(scanf("%d%d%d%d",&n,&m,&a,&b)!=EOF)
{
int ans;
int dis=0;
if(a*2==n+1&&b*2==m+1&&n==m)
{
cout<<a-1<<endl;
continue;
}
int x1=a,y1=b-1,x2=a,y2=b+1;
int x3=a-1,y3=b,x4=a+1,y4=b;
if(x1<=n&&x1>=1&&y1<=m&&y1>=1) dis=max(dis,min(x1,min(n-x1+1,y1)));
if(x2<=n&&x2>=1&&y2<=m&&y2>=1) dis=max(dis,min(x2,min(n-x2+1,m-y2+1)));
if(x3<=n&&x3>=1&&y3<=m&&y3>=1) dis=max(dis,min(y3,min(m-y3+1,x3)));
if(x4<=n&&x4>=1&&y4<=m&&y4>=1) dis=max(dis,min(y4,min(m-y4+1,n-x4+1)));
ans=max(dis,min((n+1)/2,(m+1)/2));
if(n)
cout<<ans<<endl;
}
}
HDU 5301 Buildings 数学的更多相关文章
- hdu 5301 Buildings (2015多校第二场第2题) 简单模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...
- HDU - 5301 Buildings
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- HDU 5301 Buildings(2015多校第二场)
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- HDU 5301 Buildings 建公寓(逻辑,水)
题意:有一个包含n*m个格子的矩阵,其中有一个格子已经被染黑,现在要拿一些矩形来填充矩阵,不能填充到黑格子,但是每一个填充进去的矩形都必须至少有一条边紧贴在矩阵的边缘(4条边)的.用于填充的矩形其中最 ...
- bzoj4302 Hdu 5301 Buildings
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4302 [题解] 出自2015多校-学军 题意大概是给出一个n*m的格子有一个格子(x,y)是 ...
- 数学 HDOJ 5301 Buildings
题目传送门 /* 题意:n*m列的矩阵,删除一个格子x,y.用矩形来填充矩阵.且矩形至少有一边是在矩阵的边缘上. 求满足条件的矩形填充方式中面积最大的矩形,要使得该最大矩形的面积最小. 分析:任何矩形 ...
- hdoj 5301 Buildings
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 #include <iostream> #include <stdio.h&g ...
- hdu 4296 Buildings(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others ...
随机推荐
- Ubuntu之设置应用开机自启动
前言 前面使用oricle-Linux的时候,设置开机自启动使用的是chkconfig,现在使用ubuntu的时候发现Ubuntu系统没有了RH系统中的 chkconfig命令,因此研究了一下ubun ...
- elk系列8之logstash+redis+es的架构来收集apache的日志【转】
preface logstash--> redis --> logstash --> es这套架构在讲究松耦合关系里面是最简单的,架构图如下: 解释下这个架构图的流程 首先前端log ...
- Redis 启动警告解决【转】
[root@centos224]# service redisd start :M Nov :: (it was originally set to ). _._ _.-``__ ''-._ _.-` ...
- Python 库汇总中文版
这又是一个 Awesome XXX 系列的资源整理,由 vinta 发起和维护.内容包括:Web框架.网络爬虫.网络内容提取.模板引擎.数据库.数据可视化.图片处理.文本处理.自然语言处理.机器学习. ...
- 让Linux应用更加得心应手的
1.计算文件数和目录数 下面的语句可以帮你计算有多少个文件和多少个目录 # ls -l * |grep "^-"|wc -l ---- to count files # ls - ...
- Mariadb 10.2中的json使用及应用场景思考
-- 创建示例表DROP TABLE IF EXISTS `t_base_user`;CREATE TABLE `t_base_user` ( `USER_ID` char(36) CHARACT ...
- OPENSSL问题,使用fsockopen()函数提示错误
环境配置 系统环境 CentOS7.2WDCP v3.2.2 lanmp PHP 多版本 指定使用5.6 OpenSSL 1.0.2h 3 May 2016 php.ini相关设置allow_url ...
- selector函数指针回调机制
selector可以叫做选择器,其实指的就是对象的方法,也可以理解为C语言里面的函数指针,在面向对象里面的对应概念. [self performSelector:@selector(Hidden) w ...
- 翻译:MLAPP(2.1节 概率概述)
笔者:尝试翻译MLAPP(Machine Learning: a Probabilistic Perspective)一书,供机器学习的学者参考,如有错误理解之处请指出,不胜感激!(如需转载,请联系本 ...
- bzoj 1109
思路:我们考虑dp[ i ] 表示的是 i 在指定位置上 的最大个数, dp[ i ] = max(dp[ j ] + 1) j需要满足3个条件 1. j < i 2. a[ j ] < ...