Chocolate Bar
Posted nublity
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Chocolate Bar相关的知识,希望对你有一定的参考价值。
题目描述
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
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 is given from Standard Input in the following format:
H W
H W
输出
Print the minimum possible value of Smax?Smin.
样例输入
3 5
样例输出
0
提示
In the division below, Smax?Smin=5?5=0.
提示:
一开始想的有点多,仔细想想规律就是先最大化的分成三分之一,然后在分成二分之一,从m和n两个不同的角度分,然后记录x,y,z然后取其中最大最小值做差即可;
#include <bits/stdc++.h> #define ll long long const int mod=1e9+7; using namespace std; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); ll i,j,k,m,n; ll ans=9999999999,cnt,x,y,z; ll a,b; ll minn,maxn; cin>>m>>n; a=m,b=n; if(m%3==0||n%3==0) { cout<<0<<endl; return 0; } for(i=0; i<2; i++) { m=a; n=b; if(i==0&&m!=1) { x=(m+1)/3*n; m-=(m+1)/3; } else if(i==1&&n!=1) { x=((n+1)/3)*m; n-=(n+1)/3; } for(j=0; j<2; j++) { if(j==0&&n!=1) { y=m*(n/2); z=m*(n-n/2); } else if(j==1&&m!=1) { y=n*(m/2); z=n*(m-m/2); } maxn=max(x,max(y,z)); minn=min(x,min(y,z)); ans=min(ans,maxn-minn); } } cout<<ans<<endl; return 0; }
以上是关于Chocolate Bar的主要内容,如果未能解决你的问题,请参考以下文章
codeforces 598E E. Chocolate Bar(区间dp)
在 Navigation Drawer 的每个片段中实现不同的 Action Bar 项