Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=3682
Idea: Hash. For each (x, y, z) coordinate of the cube, map to X*n*n+y*n+z, determine how many different numbers is to delete the number of cubes.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int n,m;vector<int> ans;inline int Hash (int x,int y,int z) {return x*n*n+y*n+z;} int main () {int t; scanf ("%d", &t); while (t--) {ans.clear (); scanf ("%d%d", &n,&m); for (int i=0; i<m; i++) {char ch1,ch2; int pos1,pos2; GetChar (); scanf ("%c=%d,%c=%d", &ch1,&pos1,&ch2,&pos2); if (ch1== ' Y ') {if (ch2== ' X ') {for (int z=1; z<=n; z++) Ans.push_back (Hash (pos2,pos1,z)); } else {for (int x=1; x<=n; x + +) Ans.push_back ( Hash (X,pos1,pos2)); }} else if (ch1== ' X ') {if (ch2== ' Y ') {f or (int z=1;z<=n; z++) Ans.push_back (Hash (pos1,pos2,z)); } else {for (int y=1; y<=n; y++) Ans.push_back ( Hash (Pos1,y,pos2)); }} else if (ch1== ' Z ') {if (ch2== ' Y ') {f or (int x=1; x<=n; x + +) Ans.push_back (Hash (X,POS2,POS1)); } else {for (int y=1; y<=n; y++) Ans.push_back ( Hash (POS2,Y,POS1)); }}} sort (Ans.begin (), Ans.end ()); int Num=unique (Ans.begin (), Ans.end ())-ans.begin (); printf ("%d\n", num); } return 0;}
Hdu 3682 to is an Dream Architect (Hash)