HDU 5301(Buildings-贪心构造)
Buildings
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2210 Accepted Submission(s): 624
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.
testcases.
For each testcase, only four space-separated integers,
n,m,x,y(1≤n,m≤10
2 3 2 2
3 3 1 1
1
2HintCase 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.
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-贪心构造)的更多相关文章
- HDU 5301 Buildings 数学
Buildings 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5301 Description Your current task is to m ...
- hdu 5301 Buildings (2015多校第二场第2题) 简单模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子 ...
- HDU 4296 Buildings(贪心)
题意: 给定n个建筑物,每个建筑物都有两个属性w, s,每个建筑物都有一个PDV = (Σw j)-s i .意思就是它上面的所有的w相加减去它的s,让求怎么放置这个建筑物使得每个建筑物当中PDV最大 ...
- 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)是 ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
随机推荐
- CodeForces839B[思维] Codeforces Round #428 (Div. 2)
#include <bits/stdc++.h> using namespace std; int n, k; ; ], cnt[]; void solve() { int t; cnt[ ...
- codevs 1081 线段树练习 2 区间更新 单点查询 无lazy
题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ...
- webstorm卡顿
http://blog.csdn.net/qq673318522/article/details/50583831 http://www.xiaobai8.com/Blog/1000.html
- nginx问题
1.杀死nginx之后,找不到pid http://bbs.pxecn.com/thread-122116-1-1.html
- web储存用户信息
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- mac 常用操作
1. 快速获取文件夹的位置: 打开文本 terminal 程序,将文件拖进去,路径会自己主动打印出来 2. 移动文件夹: 选中目标文件,然后使用 Command+C 复制,然后用 Command +O ...
- 收集邮票(bzoj 1426)
Description 有n种不同的邮票,皮皮想收集所有种类的邮票.唯一的收集方法是到同学凡凡那里购买,每次只能买一张,并且买到的邮票究竟是n种邮票中的哪一种是等概率的,概率均为1/n.但是由于凡凡也 ...
- scrapy实战
采用scrapy实现对股票网站的爬取 功能描述: 技术路线:scrapy 目标:获取上交所和深交所所有股票名称和交易信息并存储 实例编写: 步骤1:建立工程和spider爬虫模板 步骤2:编写spid ...
- Python学习杂记_2_格式化字符串的一些操作
name=input("Please input your name: ") sex=input("Please input your sex: ") prin ...
- 牛客网 牛客小白月赛2 B.小马过河-简单的计算几何
B.小马过河 链接:https://www.nowcoder.com/acm/contest/86/B 这个题是一个简单的几何题???套个板子就过了,就是直线上两点确定的这条直线和直线外一点的垂足的坐 ...