AtCoder:Chocolate Bar(数学)
来源:互联网 发布:石岐unity3d招聘 编辑:程序博客网 时间:2024/06/06 20:09
C - 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
思路:割法无非就两种,平行割三刀,或者先割一刀分成两半1和2,再在其中一半横着割一刀分成1,3,4,那么比较这俩情况就行了,对于第二种情况,最小的矩形要么是1要么是3或4,再分这两种情况计算就行了。
# include <bits/stdc++.h>using namespace std; typedef long long LL;int cal(int a, int b){ int c = a/2; if((LL)a+c > (LL)b*c) return (int)((LL)a+c-(LL)b*c); int x = (int)ceil(b*c*1.0/(a+c)); return max((a+c)*x-b*c, (b-x)*(a-2*c));}int cal2(int a, int b){ int c = (int)ceil(a/2.0); if(a+c > (LL)b*c) return 1e9; int x = (LL)b*c/(c+a); return max((int)((LL)b*c-(LL)x*(a+c)), (int)((LL)(b-x)*(2*c-a)));}int cal3(int a, int b){ double x = floor(b/3.0); double y = ceil(b/3.0); return (int)(y*a-x*a);}int main(){ int a, b; scanf("%d%d",&a,&b); int ans = min(cal(a, b), min(cal(b, a), min(cal2(a, b), min(cal2(b, a), min(cal3(a, b), cal3(b, a)))))); printf("%d\n",ans); return 0;}
- AtCoder:Chocolate Bar(数学)
- AtCoder:井井井 / ###(数学)
- Codeforces 598E:Chocolate Bar(DP)
- atcoder-Coloring Dominoes(组合数学)
- Educational Codeforces Round 1 E Chocolate Bar(dp)
- CodeForces 598E Chocolate Bar(DP|记忆化搜索)
- CodeForces 617 B. Chocolate(组合数学)
- Codeforces 598E Chocolate Bar
- Codeforces 598E:Chocolate Bar
- Codeforces 598E Chocolate Bar
- atcoder Moderate Differences(数学)
- HDOJ 题目4112Break the Chocolate(数学)
- codeforces 490D Chocolate(数学或搜索)
- hdoj Break the Chocolate 4112 (数学规律题)
- Educational Codeforces Round 13 C Joty and Chocolate(数学)
- codeforces-678-C. Joty and Chocolate(数学)
- CF689C Mike and Chocolate Thieves(二分答案+数学)
- Educational Codeforces Round 1 E. Chocolate Bar(记忆化搜索)
- Win10修复Linux引导
- Spring MVC 之 处理Date类型
- 一个安卓锁机病毒的分析报告
- Apache和Tomcat有什么不同,为什么要整合Apache和Tomcat
- POJ 1408 Fishnet 笔记
- AtCoder:Chocolate Bar(数学)
- USACO Section 1.1 Friday the Thirteenth
- 一个简单的蓝牙指令测试工具
- 命令工具类
- jedis分布式锁
- Arctic Network UVA
- 浏览器小结
- Vue.js路由组件vue-router的使用方法
- bzoj 2186 [Sdoi2008]沙拉公主的困惑