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 ;
}

最新文章

  1. BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
  2. 防止sql注入
  3. python中的thread
  4. leetcode 205
  5. JS 关闭 页面 浏览器 事件
  6. Neo4j Cypher运行示例
  7. 给Activity设置背景颜色
  8. 关于通过JS识别浏览器类型的方法
  9. Hummer框架平台介绍
  10. Percona-Server-5.5.33-31.1安装
  11. 【转】 Ubuntu samba服务器搭建及测试--不错
  12. Direct2D 几何图形绘制基础
  13. 第II篇PCI Express体系结构概述
  14. wpf的tab移动焦点只能在容器内部使用
  15. docker for mac 创建私有仓库
  16. struts2框架之文件下载(参考第三天学习笔记)
  17. python2.7中不同类型之间的比大小
  18. Angular之模版引用变量
  19. php支付宝手机网页支付类实例
  20. 更快的速度、更好的服务——易普优APS云排程

热门文章

  1. yoman搭建你的react-webpack应用
  2. axios 和 vue-axios
  3. leetcode第一刷_Sudoku Solver
  4. 对非正确使用浮点型数据而导致项目BUG的问题探讨
  5. 【Excle】动态更新数据下拉菜单
  6. 使用history.pushState()和popstate事件实现AJAX的前进、后退功能
  7. android-pull方式解析xml文件以及XML文件的序列化
  8. Matlab、R向量与矩阵操作
  9. 关于POI 中单元格背景色设置(转)
  10. GEEK学习笔记— —程序猿面试宝典笔记(三)