HDU 3682 To Be an Dream Architect

时间:2022-12-16 22:40:32

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3682

题目大意:给一个三维立方体,每次消除一行平行与坐标轴的小立方体(边长1),求一共消除了多少块。

分析:说不上分析了,给每一块小立方体一个标号,方法随便,哈希就可以了,不过不知道为什么我的哈希一直TLE,不知道是写错了还是怎么回事,无奈快排一下写了。

附代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,ans,Case;
#define MaxN 1010
int tot;
int a[MaxN*MaxN];

void init()
{
char ch1,ch2,tch;
int t1,t2;
tot=0;
ans=0;
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)
{
scanf("%c%c%c%d%c%c%c%d",&tch,&ch1,&tch,&t1,&tch,&ch2,&tch,&t2);
if (ch1=='X' && ch2=='Y')
for (int j=1;j<=n;j++)
tot++,a[tot]=t1*n*n+t2*n+j;
if (ch1=='Y' && ch2=='X')
for (int j=1;j<=n;j++)
tot++,a[tot]=t2*n*n+t1*n+j;
if (ch1=='X' && ch2=='Z')
for (int j=1;j<=n;j++)
tot++,a[tot]=t1*n*n+j*n+t2;
if (ch1=='Z' && ch2=='X')
for (int j=1;j<=n;j++)
tot++,a[tot]=t2*n*n+j*n+t1;
if (ch1=='Y' && ch2=='Z')
for (int j=1;j<=n;j++)
tot++,a[tot]=j*n*n+t1*n+t2;
if (ch1=='Z' && ch2=='Y')
for (int j=1;j<=n;j++)
tot++,a[tot]=j*n*n+t2*n+t1;
}
sort(a+1,a+tot+1);
for (int i=1;i<=tot;i++)
if (a[i]!=a[i-1]) ans++;
}

int main()
{
freopen("in","r",stdin);
freopen("out","w",stdout);
scanf("%d",&Case);
while (Case--)
{
init();
printf("%d\n",ans);
}
return 0;
}