hdu 5301 Buildings
2015-07-24 16:56
393 查看
题意:在一个n*m的矩形中,要放置很多小矩形,每个矩形必须与大矩形的边界相接触,其中有一块1*1的必须空着,他的坐标是x,y。现在问放置的小矩形面积最大值最少是多少?
分析:因为每个小矩形要和边界互相接触,所以每个小矩形都是形如1*a这样的矩形,这样才能保证面积最小,在没有空着的矩形的情况下,最小的矩形面积肯定是1*(n+1)/2,
n < m;但是若放置了一个空的1*1的矩形,那么受影响的只有那个矩形所在的一行和一列。
以下附上代码:
分析:因为每个小矩形要和边界互相接触,所以每个小矩形都是形如1*a这样的矩形,这样才能保证面积最小,在没有空着的矩形的情况下,最小的矩形面积肯定是1*(n+1)/2,
n < m;但是若放置了一个空的1*1的矩形,那么受影响的只有那个矩形所在的一行和一列。
以下附上代码:
#include <algorithm> #include <iostream> #include <sstream> #include <fstream> #include <cstring> #include <cstdio> #include <vector> #include <cctype> #include <cmath> #include <stack> #include <queue> #include <list> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned long long ull; int n,m; int x,y; int main() { while(scanf("%d%d%d%d",&n,&m,&x,&y) != EOF){ if(n > m) { swap(n,m); swap(x,y); } if(n == 1){ printf("1\n"); } else if(n == m && (n & 1) && x == y && y == (m+1)/2){ printf("%d\n",n/2); } else{ int up = x-1; int down = n-x; int left = y; int right = m-y+1; if(min(left,right) > (n+1)/2 && x != (n+1)/2){ printf("%d\n",min(max(up,down),min(left,right))); } else printf("%d\n",(n+1)/2); } } return 0; } /* 5 5 3 3 2 5 5 3 2 3 1 100 1 50 1 6 9 2 4 4 5 9 2 3 3 3 5 2 3 2 */
相关文章推荐
- 注意 ExecuteNonQuery() 返回值 问题
- jsoncpp-0.5,支持uint64
- iOS Human Interface Guidelines(原创翻译) 目录
- Building Accessibility Services
- UILabel长度自适应内部字符串NSString纪录
- Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard'
- Snail—UI学习之导航视图控制器UINavigationController(系统)
- 【源代码】java.util.Stack & Queue
- 给UITextField设置图标
- UITableView 使用 selectRowAtIndexPath 不能默认选中cell的问题
- 以ValueProvider为核心的值提供系统3: ValueProviderFactory
- 以ValueProvider为核心的值提供系统2: DictionaryValueProvider
- 以ValueProvider为核心的值提供系统1: NameValueCollectionValueProvider
- 使用百度编辑器时,报错:从客户端("...)中检测到有潜在危险的 Request.Form 值
- iOS开发-UITextField手机号和邮箱验证
- jq ui
- HDU 4126 Genghis Khan the Conqueror MST + 树形DP 2011年福州现场赛F题
- UIPopoverController中UITableViewController 中selectRowAtIndexPath: animated:scrollPosition滚动不到的解决方法
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
- uitableview style类型为Grouped时,去掉上面空白的方法