HDU 3682 To Be an Dream Architect

题目链接: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;
}

转载于:https://www.cnblogs.com/evan-oi/archive/2012/02/28/2372060.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值