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 ...
随机推荐
- 回溯算法_01背包问题_Java实现
原文地址:http://blog.csdn.net/ljmingcom304/article/details/50314839 本文出自:[梁敬明的博客] 1.回溯算法 回溯算法也叫试探法,通俗的将就 ...
- Windows 7 64 位操作系统安装 Ubuntu 17.10
一.准备工作 1. DiskGenius:分区工具,为 Linux 建立单独的分区.(Linux 公社下载源) 2. UUI:Universal USB Installer,通用 U 盘安装器,用来制 ...
- linux删除第几天日志【原创】
cat del.sh #!/bin/bash thirty=`date -d '30days ago' +%Y-%m-%d` cd $ #删除输入路径下第30天的日志文件 find . -name & ...
- Jmeter命令行选项
示例:jmeter.bat -n -j %tmp%\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%%time:~ ...
- YAML中使用Jinja模板以{{ foo }}开头需要整行加双引号
YAML陷阱 YAML语法要求如果值以{{ foo }}开头的话我们需要将整行用双引号包起来.这是为了确认你不是想声明一个YAML字典.该知识点在 YAML 语法 页面有所讲述. 这样是不行的: - ...
- 记一次spring boot中MongoDB Prematurely reached end of stream的异常解决
在spring boot项目中使用了mongodb,当一段时间没有操作mongodb,下次操作mongodb时就会出现异常.异常如下: org.springframework.data.mongodb ...
- java基础4 函数
本文知识点(目录): 1.函数的概述 2.函数的格式 3.自定义函数 4.函数的特点 5.函数的应用 6.函数的重载 1.函数的概述 发现不断进行加法运算,为了提高代码的 ...
- BestCoder #88(1001 1002)
Find Q Accepts: 392 Submissions: 780 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131 ...
- Windows内核执行体对象管理器的操作过程与分析
我之前写过一个有关于对象管理的读书笔记.但是这篇文章与前面的不同,这是我个人对对象管理器到底是什么的一个分析,而且也是直接对WRK代码进行的阅读. 执行体对象即我们通常所言的内核对象,我们知道Wind ...
- 解决wordpress无法发送邮件的问题|配置好WP-Mail-SMTP的前提
我的WordPress主机是万网的,配置WP-Mail-SMTP时一直无法发送邮件,导致设置失败.经过多次询问度娘才找到了解决wordpress无法发送邮件的方法,在这里把这个wordpress技巧分 ...