Chocolate Bar

Posted happy_code

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 份,且,边长为整数,问切出来的最大面积减最小面积的最小值是多少?

 

//竟然是一个暴力题,枚举所有切割情况

 

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define LL long long
 4 #define INF (1LL<<62)
 5 
 6 LL slv(LL x,LL y,LL s)
 7 {
 8     LL X = x/2,Y = y/2;
 9     return min (
10         max( max(abs(X*y-s),abs((x-X)*y-s)), abs(X*y-(x-X)*y) ),
11         max( max(abs(x*Y-s),abs((y-Y)*x-s)), abs(Y*x-(y-Y)*x) )
12     );
13 }
14 
15 int main()
16 {
17     LL h,w;
18     cin>>h>>w;
19     LL ans = INF;
20     for (int i=1;i<=h;i++)
21         ans = min (ans,slv(h-i,w,i*w));
22     for (int i=1;i<=w;i++)
23         ans = min (ans, slv(w-i,h,i*h));
24     cout<<ans<<endl;
25     return 0;
26 }
View Code

 

 

 

以上是关于Chocolate Bar的主要内容,如果未能解决你的问题,请参考以下文章

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

在 Navigation Drawer 的每个片段中实现不同的 Action Bar 项

在 Activity App Bar 上按下后转到带有它被调用的片段的父 Activity

带有片段的标题栏与列表视图重叠

jquery 冒号转义 为啥双斜杠

类外功能重载未见