Chocolate Bar(暴力)
Chocolate Bar
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize Smax - Smin, where Smax is the area (the number of blocks contained) of the largest piece, and Smin is the area of the smallest piece. Find the minimum possible value of Smax−Smin.
Constraints
- 2≤H,W≤105
Input
Input is given from Standard Input in the following format:
H W
Output
Print the minimum possible value of Smax−Smin.
Sample Input 1
3 5
Sample Output 1
0
In the division below, Smax−Smin=5−5=0.
Sample Input 2
4 5
Sample Output 2
2
In the division below, Smax−Smin=8−6=2.
Sample Input 3
5 5
Sample Output 3
4
In the division below, Smax−Smin=10−6=4.
Sample Input 4
100000 2
Sample Output 4
1
Sample Input 5
100000 100000
Sample Output 5
50000
//问有一块 h*w 的木板,要恰好切成 3 份,且,边长为整数,问切出来的最大面积减最小面积的最小值是多少?
//竟然是一个暴力题,枚举所有切割情况
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define INF (1LL<<62) LL slv(LL x,LL y,LL s)
{
LL X = x/,Y = y/;
return min (
max( max(abs(X*y-s),abs((x-X)*y-s)), abs(X*y-(x-X)*y) ),
max( max(abs(x*Y-s),abs((y-Y)*x-s)), abs(Y*x-(y-Y)*x) )
);
} int main()
{
LL h,w;
cin>>h>>w;
LL ans = INF;
for (int i=;i<=h;i++)
ans = min (ans,slv(h-i,w,i*w));
for (int i=;i<=w;i++)
ans = min (ans, slv(w-i,h,i*h));
cout<<ans<<endl;
return ;
}
最新文章
- BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
- 防止sql注入
- python中的thread
- leetcode 205
- JS 关闭 页面 浏览器 事件
- Neo4j Cypher运行示例
- 给Activity设置背景颜色
- 关于通过JS识别浏览器类型的方法
- Hummer框架平台介绍
- Percona-Server-5.5.33-31.1安装
- 【转】 Ubuntu samba服务器搭建及测试--不错
- Direct2D 几何图形绘制基础
- 第II篇PCI Express体系结构概述
- wpf的tab移动焦点只能在容器内部使用
- docker for mac 创建私有仓库
- struts2框架之文件下载(参考第三天学习笔记)
- python2.7中不同类型之间的比大小
- Angular之模版引用变量
- php支付宝手机网页支付类实例
- 更快的速度、更好的服务——易普优APS云排程