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

Chocolate Bar(暴力)的更多相关文章

  1. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  2. Codeforces Problem 598E - Chocolate Bar

    Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...

  3. Educational Codeforces Round 1 E. Chocolate Bar dp

    题目链接:http://codeforces.com/contest/598/problem/E E. Chocolate Bar time limit per test 2 seconds memo ...

  4. codeforces 598E E. Chocolate Bar(区间dp)

    题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. Codeforces 598E:Chocolate Bar

    E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. CodeForces 598E Chocolate Bar

    区间DP预处理. dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价. #include<cstdio> #include<cstring> #include ...

  7. cf 450c Jzzhu and Chocolate

    Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. codeforces 490 D Chocolate

    题意:给出a1*b1和a2*b2两块巧克力,每次可以将这四个数中的随意一个数乘以1/2或者2/3,前提是要可以被2或者3整除,要求最小的次数让a1*b1=a2*b2,并求出这四个数最后的大小. 做法: ...

  9. Codeforces 490D Chocolate

    D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. IOS Exception2 this class is not key value coding-compliant for the key Click

    2015-06-16 23:00:53.706 MyIOSPackage[823:280049] *** Terminating app due to uncaught exception 'NSUn ...

  2. attempt to dereference a generic a pointer(转)

    在Linux下的GDB环境中,用p   命令查看一个void   *型的变量的时候,提示为:  "attempt   to   dereference   a   generic   a   ...

  3. Spring 配置dataSource和sessionFactory

    记得导入dbcp和pool的jar包.   <?xml version="1.0" encoding="UTF-8"?> <beans xml ...

  4. UITabBarController超强拓展

    代码地址如下:http://www.demodashi.com/demo/11901.html 一.运行效果图 二.项目结构截图 三.主要API 我们主要关注的是TLTabBarController, ...

  5. Nginx-安装依赖及配置详解

    依赖 在安装Nginx之前, 需确保系统已经安装了gcc. openssl-devel. pcre-devel和zlib-devel软件库 配置 Nginx的配置文件nginx.conf位于其安装目录 ...

  6. Spark on Yarn 集群运行要点

    实验版本:spark-1.6.0-bin-hadoop2.6 本次实验主要是想在已有的Hadoop集群上使用Spark,无需过多配置 1.下载&解压到一台使用spark的机器上即可 2.修改配 ...

  7. c++ 类内部 使用 new delete

    低级错误: /** * @clusterNums 默认为5 分类数目 * @xyVector 处理后点云数据 x y顺序存储 */ int GMM::runGMM(int clusterNums, c ...

  8. Windows内存管理的方式

    一.内存的概念 1. 物理内存:即插在主板上的内存条.他是固定的,内存条的容量多大,物理内存就有多大(集成显卡系统除外). 但是如果程序运行很多或者程序本身很大的话,就会导致大量的物理内存占用,甚至导 ...

  9. [原创]FreeSWITCH命令:uuid_dual_transfer

    该篇文章主要介绍FreeSWITCH的API命令uuid_dual_transfer的用法. 命令介绍 该命令用于同时将两条腿进行转移,并且是可以转移到不同的方向. -USAGE: <A-des ...

  10. 知也atitit.解决struts2 SpringObjectFactory.getClassInstance NullPointerException  v2 q31无涯 - I

    atitit.解决struts2 SpringObjectFactory.getClassInstance NullPointerExceptionv2 q31 1. #--现象 java.lang. ...