icpc:problems:755b_coloring_rectangles
problems | |
---|---|
名称 | Coloring Rectangles |
题目编号 | 755B |
题目链接 | codeforces.com/… |
来源 | CodeForces |
算法分类 | 贪心 |
难易程度 | 小有难度 |
Coloring Rectangles
想法
题目需要考虑的情况有点多,总的来说就是尽可能的拆成1*3,如果遇到了1*4就不要拆,如果遇到了2*4,就需要考虑将右边多余出来的部分组合在一起。
代码实现
#include<cstdio>//uncle-lu #include<algorithm> int check(int x, int y) { int temp = x/3 * y; if(x % 3 == 1){ temp += y / 3 + (y%3 ? 1 : 0); } if(x % 3 == 2){ temp += (y / 3) * 2 + y%3; } return temp; } int main() { int t; scanf("%d", &t); for(int i=1; i<=t; ++i) { int n, m; scanf("%d %d", &n, &m); int mi = std::min(check(n, m), check(m, n)); printf("%d\n", mi); } return 0; }
/app/www/public/data/pages/icpc/problems/755b_coloring_rectangles.txt · 最后更改: 2023/09/30 14:04 由 温婕莺