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.

2a9b2ef47b750c0b7ba3e865d4fb4203.png

Sample Input 2

4 5

Sample Output 2

2

In the division below, Smax−Smin=8−6=2.

a42aae7aaaadc4640ac5cdf88684d913.png

Sample Input 3

5 5

Sample Output 3

4

In the division below, Smax−Smin=10−6=4.

eb0ad0cb3185b7ae418e21c472ff7f26.png

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

 

 

 

转载于:https://www.cnblogs.com/haoabcd2010/p/6884598.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值