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 ...
随机推荐
- plsql连接oracle数据库
步骤 (1)线上安装oracle数据库(已配好) (2)本地远程连接.安装oracle客户端(运行时) (3)安装plsql. (4)oracle客户端可以不用配置,直接在plsql中数据访问验证
- Data truncation: Data too long for column
是字符集问题引起的,用show full fields from + 表名就可以看出你的列的编码格式把它改成GBK或者GB2312.uTF-8.如果还不行的话,把你表的编码格式也改成上面的编码格式,我 ...
- 基于MaterialDesign设计风格的妹纸app的简单实现
代码地址如下:http://www.demodashi.com/demo/11644.html *今天看了郭神的第二行代码,深深的被MaterialDesign的设计风格所吸引,然后就照例做了一个小D ...
- Atitit.虚拟机与指令系统的设计
Atitit.虚拟机与指令系统的设计 1. 两种计算模型 ,堆栈机和状态机(基于寄存器的虚拟机1 1.1.1. 堆栈机1 1.1.2. 状态机2 2. 为什么状态机比堆栈机快呢?3 2.1. Sta ...
- JPA ID生成策略(转---)
尊重原创:http://tendyming.iteye.com/blog/2024985 JPA ID生成策略 @Table Table用来定义entity主表的name,catalog,schema ...
- C++学习笔记34 模版的原理
模版在C++中具有很重要的地位.STL就是大量运用模版写出来的. 模版的长处我就不一一列举了.这里我仅仅说一下模版的原理. 当编译器遇到模版方法定义的时候,编译器进行语法检查,可是并不会编译模版.编译 ...
- PHP修改memory_limit的三种办法
PHP修改memory_limit的三种办法 2010-06-11 10:57:11 分类: 可能是分词程序的问题.只要搜索的字段达到十个汉字以上,就会出现诸如以下的错误 Fatal error: ...
- c++ 请抛弃匈牙利命名法 - 变量命名代码风格的建议。
我只针对c++码农们讲,其他语言不了解不过应该大同小异.曾几何时翻开21天学通c++系列等脑残入门书,都以匈牙利命名法示人(DWORD dwXXX, int nXXX, string strXXX). ...
- phxsql安装小记
PhxSQL具有服务高可用.数据强一致.高性能.运维简单.和MySQL完全兼容的特点. 服务高可用:PhxSQL集群内只要多数派节点存活就能正常提供服务:出于性能的考虑,集群会选举出一个Master节 ...
- MySQL和hive对比表结构脚本
#!/bin/bash source /etc/profile runlog='/tmp/zewei/check_schema_log' hive_database_schema=/tmp/hive_ ...