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. 利用Bootstrap制作一个流行的网页

    首先是html承载内容: <!DOCTYPE html> <html lang="zh_CN"> <head> <meta charset ...

  2. 【React Native开发】React Native控件之Image组件解说与美团首页顶部效果实例(10)

    ),React Native技术交流4群(458982758),欢迎各位大牛,React Native技术爱好者增加交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章技术推送! Im ...

  3. python 对比学习

    python和java面向对象的不同 1.属性和方法 java中类的属性(static)除外,对象全部独立拥有: 而python中类的属性,其实例对象一个字段都没有.底层是这么搞的: 对象object ...

  4. 非等高cell实战--实现微博页面

    代码地址如下:http://www.demodashi.com/demo/11639.html 前言 学习过UITableView.AutoLayout以及MVC的相关知识,接下来通过一个微博页面实战 ...

  5. Spring使用经验之Listener综述

    Note:Spring使用版本是4.1.6.RELEASE 1. ContextLoaderListener最基本的SpringListener,加载Spring配置文件 配置名为contextCon ...

  6. windowns 查看端口占用

    开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选&qu ...

  7. Codeforces Round #244 (Div. 2)——Checkposts

    题目链接 题意: 给定n个点,每一个点有一个权值的有向图.如今须要选定一些点,使得这些点权值和最小.且满足:假设i能到达j且j能到达i,那么i.j能够仅仅选一个 分析: 强联通模板题 //使用时仅仅更 ...

  8. Git实战(四)状态转换

    上次的Git实战(三)环境搭建博文.我们大致解说了一下git的环境安装,今天我们解说一下Git的状态转换. 学习版本号控制工具.对工具进行版本号控制之间的状态转换很重要.毕竟Git仅仅是一个工具.假设 ...

  9. 时间序列 R 读书笔记 04 Forecasting: principles and practice

    本章開始学习<Forecasting: principles and practice> 1 getting started 1.1 事件的可预言性 一个时间能不能被预言主要取决于以下三点 ...

  10. MySQL 汉字转拼音

    一 . fristPinyin : 此函数是将一个中文字符串的第一个汉字转成拼音字母 (例如:"中国人"->Z) )) ) CHARSET utf8 BEGIN ); )), ...