题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3682
思路:Hash。对于每个(x,y,z)坐标的立方体,映射为x*n*n+y*n+z,判断有多少个不同数字即为删去立方体个数。
#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') { for(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') { for(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; }
时间: 2024-10-05 14:32:14