Poj 2160 Box simulation and poj2160box Simulation
Question:
Give the length of six boards to determine whether they can form a cube.
Analysis:
Simulation, first determine whether the six boards can be divided into three groups of completely equal boards, and then determine whether the three groups of boards can form a cube.
Code:
// Poj 2160 // sep9 # include <iostream> # include <algorithm> using namespace std; int vis [8]; int x [8], y [8]; int a [8]; int main () {int I, j; for (I = 0; I <6; ++ I) {scanf ("% d ", & x [I], & y [I]); if (x [I]> y [I]) swap (x [I], y [I]);} int cnt = 0, t = 0; memset (vis, 0, sizeof (vis); for (I = 0; I <6; ++ I) {if (vis [I] = 0) {vis [I] = 1; for (j = 0; j <6; ++ j) if (vis [j] = 0 & x [j] = x [I] & y [j] = y [I]) {vis [j] = 1; a [t ++] = x [I]; a [t ++] = y [I]; ++ cnt; break ;}}if (cnt = 3) {sort (a, a + 6 ); if (a [0] = a [1] & a [2] = a [3] & a [4] = a [5]) printf ("POSSIBLE"); elseprintf ("IMPOSSIBLE");} elseprintf ("IMPOSSIBLE ");}