UVa 1587 - Box

来源:互联网 发布:交通可视化仿真软件 编辑:程序博客网 时间:2024/06/07 21:11

題目:給你六個矩形,問能不能用它們拼成一個長方體。

分析:搜索,枚舉。直接枚舉所有面的排列,以及各排列下,長寬互換的情況,判斷即可。

            判斷條件,對面相同,一個角處三個面的交邊相同。

說明:做的有點麻煩╮(╯▽╰)╭。

#include <cstdio>int box[6][2], plane[6][2];int used[6], save[6];int dfs(int n){if (n > 5) {for (int i = (1<<6)-1; i >= 0; -- i) {for (int j = 0; j < 6; ++ j)if (i&(1<<j)) {box[j][0] = plane[save[j]][1];box[j][1] = plane[save[j]][0];}else {box[j][0] = plane[save[j]][0];box[j][1] = plane[save[j]][1];}if (box[0][0] == box[2][0] && box[0][1] == box[2][1] &&box[1][0] == box[3][0] && box[1][1] == box[3][1] &&box[4][0] == box[5][0] && box[4][1] == box[5][1] &&box[0][0] == box[1][0] &&box[4][0] == box[1][1] && box[4][1] == box[0][1])return 1;}return 0;}else {for (int i = 0; i < 6; ++ i)if (!used[i]) {used[i] = 1;save[n] = i;if (dfs(n+1))return 1;used[i] = 0;}return 0;}}int main(){while (~scanf("%d%d",&plane[0][0],&plane[0][1])) {for (int i = 1; i < 6; ++ i) scanf("%d%d",&plane[i][0],&plane[i][1]);for (int i = 0; i < 6; ++ i)used[i] = 0;if (dfs(0))puts("POSSIBLE");else puts("IMPOSSIBLE");}    return 0;}


0 0
原创粉丝点击