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 份,且,边长为整数,问切出来的最大面积减最小面积的最小值是多少?
//竟然是一个暴力题,枚举所有切割情况
#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(暴力)的更多相关文章
- Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索
E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...
- Codeforces Problem 598E - Chocolate Bar
Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...
- 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 ...
- codeforces 598E E. Chocolate Bar(区间dp)
题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 598E:Chocolate Bar
E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- CodeForces 598E Chocolate Bar
区间DP预处理. dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价. #include<cstdio> #include<cstring> #include ...
- cf 450c Jzzhu and Chocolate
Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 490 D Chocolate
题意:给出a1*b1和a2*b2两块巧克力,每次可以将这四个数中的随意一个数乘以1/2或者2/3,前提是要可以被2或者3整除,要求最小的次数让a1*b1=a2*b2,并求出这四个数最后的大小. 做法: ...
- Codeforces 490D Chocolate
D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
随机推荐
- 【原】Ubuntu下使用teamviewer
想尝试直接使用Xmanager打开Ubuntu桌面版,结果一直存在问题,迂回一下,尝试使用teamviewer解决,结果OK.办法如下: 在Ubuntu中,下载teamviewer,通过Windows ...
- mac中yeoman构建你的项目
一开始用在mac中构建一个项目就遇到一个很奇怪的事, 做好各种准备工作后,我开始创建一个angular01作为测试目录,结果运行yo脚手架之后,选择angular工作流进行构建项目,出来的结果我开始慌 ...
- PowerDesigner 将表的字段name属性设置到comment凝视
1.首先copy以下的vbs脚本.并将其另存为name2comment.vbs '*********************************************************** ...
- javascript获取日期的年,月,日
var date = new Date(strTime); return date.getFullYear()+"-"+(date.getMonth()+1)+"-&qu ...
- 把.apk传到站点server下载
刚刚解决的一个问题,做好的apk上传到server,通过訪问链接下载apk. 解决方法:设置IIS的MIME类型,让IIS web下载支持包含APK等文件在内的多文件类型 1.打开IIS站点,右键属性 ...
- python学习笔记之pdb调试
之前一直说要学python可还是一直停留在看的层面,昨天大神手把书教我pdb调试,说要摆脱IDE集成开发环境编程,感激不尽,立一个flag,python一定要入门! 1.进入方式 1)windows ...
- 设置U盘启动
利用快捷键来设置U盘启动,利用快捷键启动相对来说比较简单快捷,推荐大家使用(重要提醒:选择热键前,请先插入U盘) 组装机主板 品牌笔记本 品牌台式机 主板品牌 启动按键 笔记本品牌 启动按键 台式机品 ...
- centos7安装thrift
1. 升级所有软件包 yum -y update 2.安装开发工具 yum -y groupinstall "Development Tools" 3.安装wget yum -y ...
- Linux C 中 open close read write 使用实例
这里实现的是将文件cody.txt中的内容拷贝到to_cody.txt中去. 1 /* ======================================================== ...
- 用JWT技术为SpringBoot的API增加授权保护(转),需要自己实现userdetailservice接口
转自:https://blog.csdn.net/haiyan_qi/article/details/77373900 概述 示例 https://github.com/qihaiyan/jwt-bo ...