码迷,mamicode.com
首页 > 其他好文 > 详细

Hdu 3682 To Be an Dream Architect(Hash)

时间:2016-08-16 10:42:21      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

题目地址: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;
}



Hdu 3682 To Be an Dream Architect(Hash)

标签:

原文地址:http://blog.csdn.net/wang2147483647/article/details/52217429

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!