Buildings

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 2210    Accepted Submission(s): 624

Problem 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 numbera
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
Case 1 :

You can split the floor into five $1 \times 1$ apartments. The answer is 1. Case 2:

You can split the floor into three $2 \times 1$ apartments and two $1\times 1$ apartments. The answer is 2.
If you want to split the floor into eight $1 \times 1$ apartments, it will be unacceptable because the apartment located on (2,2) can't have windows.
 
Author
XJZX
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5395 5394 5393 

pid=5392">5392 5391 

 

假设没有坏点 ans=(min(n,m)+1)/2

假设n=m=奇数,x,y在中间 ans‘=(min(n,m)+1)/2-1

否则,x,y用对称性挪到左上角

此时对于宿舍楼要么竖着分max(y,m-y+1)+1

要么横着分 min(x,n-x+1)

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int main()
{
// freopen("B.in","r",stdin); int n,m,x,y;
while(scanf("%d%d%d%d",&n,&m,&x,&y)==4) {
if (n<m) swap(n,m),swap(x,y); int ans=(min(n,m)+1)/2;
if (n==m&&x==y&&n==2*x-1)
{
cout<<ans-1<<endl; continue;
} x=min(x,n-x+1),y=max(y,m-y+1); int ans2=min(x,y-1); cout<<max(ans2,ans)<<endl; } return 0;
}

HDU 5301(Buildings-贪心构造)的更多相关文章

  1. HDU 5301 Buildings 数学

    Buildings 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5301 Description Your current task is to m ...

  2. hdu 5301 Buildings (2015多校第二场第2题) 简单模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...

  3. HDU 4296 Buildings(贪心)

    题意: 给定n个建筑物,每个建筑物都有两个属性w, s,每个建筑物都有一个PDV = (Σw j)-s i .意思就是它上面的所有的w相加减去它的s,让求怎么放置这个建筑物使得每个建筑物当中PDV最大 ...

  4. HDU - 5301 Buildings

    Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...

  5. HDU 5301 Buildings(2015多校第二场)

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  6. 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 ...

  7. HDU 5301 Buildings 建公寓(逻辑,水)

    题意:有一个包含n*m个格子的矩阵,其中有一个格子已经被染黑,现在要拿一些矩形来填充矩阵,不能填充到黑格子,但是每一个填充进去的矩形都必须至少有一条边紧贴在矩阵的边缘(4条边)的.用于填充的矩形其中最 ...

  8. bzoj4302 Hdu 5301 Buildings

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4302 [题解] 出自2015多校-学军 题意大概是给出一个n*m的格子有一个格子(x,y)是 ...

  9. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

随机推荐

  1. ms sqlserver数据库主文件特别大怎么办

    因为项目中需要复制数据库,作为外网测试的数据库,但是数据库特别大,复制特别费劲,即使只复制主文件,主文件也特别大. 然后百度了下,发现数据库有个收缩功能,数据库右键——任务——收缩,可以对数据库进行收 ...

  2. 用Excel的分列功能格式化时间

    从数据库导出的时间是带有毫秒的,怎么变成短的时间呢? 首先在时间列后面插入一列: 第二,点击数据菜单,点击分列,下一步,然后输入分割符号,然后就变成了两列.

  3. 【bzoj4259/bzoj4503】残缺的字符串/两个串 FFT

    bzoj4259 题目描述 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有 ...

  4. [openjudge6043]哆啦A梦的时光机

    [openjudge6043]哆啦A梦的时光机 试题描述 哆啦A梦有一个神奇的道具:时光机.坐着它,大雄和他的伙伴们能穿越时空,回到过去或者去到未来. 有一天,大雄和他的伙伴们想穿越时空进行探险,可是 ...

  5. Optimal Marks(optimal)

    Optimal Marks(optimal) 题目描述 定义无向图边的值为这条边连接的两个点的点权异或值. 定义无向图的值为无向图中所有边的值的和. 给定nn个点mm条边构成的图.其中有些点的权值是给 ...

  6. bzoj1093【ZJOI2007】最大半联通子图

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1093 sol  :一开始理解错题意了QAQ,还莫名其妙写挂了QAQ,调了半天 首先显然一个强联 ...

  7. python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

    运行出现如下错误 uncode编码警告:在unicode等价比较中,把两个参数同时转换为unicode编码失败.中断并认为他们不相等. windows下的字符串str默认编码是ascii,而pytho ...

  8. Javascript&Html-location对象

    Javascript&Html-location对象 location对应是BOM最有用的对象之一,她提供了当前窗口中加载的文档的信息,并提供了一些导航的功能.location对象有一个特别的 ...

  9. 1月24日考试(ftp密码)

    错因分析 ♦对文件的保存不够恰当,例如第一题和第三题的题目,我是真的很愤怒,第一题在我写了一个多小时,终于样例成功.可是当我再一次打开文件时,里面只有我最开始的代码,谁可以告诉我这是为什么(我绝对保存 ...

  10. Linux 环境下安装配置 TigerVNC Server 并启用当前会话远程服务(X0VNC)

    曾经喜欢用 RealVNC Server 实现 Linux/Windows 的远程控制,因为 RealVNC 为收费商业软件,支持文件传输,性能优化方面也做得不错.但 RealVNC 从 5.0 版本 ...