Hdu 3682 To Be an Dream Architect(Hash)

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

Hdu 3682 To Be an Dream Architect(Hash)的相关文章

HDU 3682 To Be an Dream Architect:查重【三维坐标系中点在实数上的映射】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3682 题意: 有一个n*n*n的立方体,左下角坐标为(1,1,1),接下来进行m次操作. 每个操作形如这样:"axis_1=a,axis_2=b". 例如:"x=3,y=1",意思是消去所有x=3,y=1的方块. RT: 题解: 问题的唯一矛盾在于:一个位置的方块可能被多次消去. 所以... (1)由于每一个坐标(x,y,z)在实数中有唯一映射:x*n*n+y*n+z,

[水+思路] hdu 3682 To Be an Dream Architect

题意: 就是有n*n*n个木块,然后给你m条三维的直线 问这些直线能够消掉多少个木块 思路: 其实就是求m条直线有几个交点 然后就是一个双重循环解决 然后读入的时候需要判重 用三个1000*1000的数组来实现. 注意 3 3 Y=2,Z=2 X=2,Y=2 X=2,Z=2 答案应该是7而不是6,因为三条线交在同一点上. 6的原因是在判断第一条线的时候 和后面两个都有交点,但是交点是同一个 其实只有1个. 这里的判重方法就是,用这条线没有的那个坐标进行判重. 因为对于Y=2,Z=2 交点的话只有

HDU 5024 Wang Xifeng&#39;s Little Plot (搜索)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 157    Accepted Submission(s): 105 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

HDU 5024 Wang Xifeng&#39;s Little Plot (bfs)

Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin.

hdu 1507 Uncle Tom&#39;s Inherited Land*(二分)

Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1853    Accepted Submission(s): 769 Special Judge Problem Description Your old uncle Tom inherited a piece of land fr

hdu 4956 Poor Hanamichi BestCoder Round #5(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956 Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7    Accepted Submission(s): 4 Problem Description Hanamichi is taking part in

HDU 4001 To Miss Our Children Time (动态规划)

To Miss Our Children Time Problem Description Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;s Wild Numbers(数学)

题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Description A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and

HDU - 4971 A simple brute force problem. (DP)

Problem Description There's a company with several projects to be done. Finish a project will get you profits. However, there are some technical problems for some specific projects. To solve the problem, the manager will train his employee which may