ZOJ-3706

来源:互联网 发布:黑咔相机软件 编辑:程序博客网 时间:2024/04/28 10:59

水题一道,求组合数最多的拆分,直接枚举就行了

#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;namespace{int mass[3][3];bool flag[201];int solve(int a, int b, int c){memset(flag, 0, sizeof(flag));memset(mass, 0, sizeof(mass));mass[0][1] = a;mass[0][2] = -a;mass[1][1] = b;mass[1][2] = -b;mass[2][1] = c;mass[2][2] = -c;int res = 0;for (int i = 1; i < 27; i++){int sum = abs(mass[0][i / 9] + mass[1][i / 3 % 3] + mass[2][i % 3]);if (sum && !flag[sum]){flag[sum] = true;res++;}}return res;}}int main(){int T, x, y;scanf("%d", &T);while (T--){scanf("%d %d", &x, &y);int maxx = 0;for (int i = 1; i <= x / 2; i++)maxx = max(solve(i, x - i, y), maxx);for (int j = 1; j <= y / 2; j++)maxx = max(solve(j, y - j, x), maxx);printf("%d\n", maxx);}return 0;}


0 0