hdu3682 To Be an Dream Architect

http://acm.hdu.edu.cn/showproblem.php?pid=3682

To Be an Dream Architect

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2868    Accepted Submission(s): 826

Problem Description

The “dream architect” is the key role in a team of “dream extractors” who enter other’s dreams to steal secrets. A dream architect is responsible for crafting the virtual world that the team and the target will dream into. To avoid the target noticing the world
is artificial, a dream architect must have powerful 3D imagination.

Cobb uses a simple 3D imagination game to test whether a candidate has the potential to be an dream architect. He lets the candidate imagine a cube consisting of n×n×n blocks in a 3D coordinate system as Figure 1. The block at bottom left front corner is marked
(1, 1, 1) and the diagonally opposite block is marked (n, n, n). Then he tells the candidate that the blocks on a certain line are eliminated. The line is always parallel to an axis. After m such block eliminations, the candidate is asked to tell how many
blocks are eliminated. Note that one block can only be eliminated once even if it is on multiple lines.

Here is a sample graph according to the first test case in the sample input:

Input

The first line is the number of test cases.

In each test case, the first line contains two integers n and m( 1 <= n <= 1000, 0 <= m <= 1000).,meaning that the cube is n x n x n and there are m eliminations.

Each of the following m lines represents an elimination in the following format:

axis_1=a, axis_2=b

where axis_i (i=1, 2) is ‘X’ or ‘Y’, or ‘Z’ and axis_1 is not equal to axis_2. a and b are 32-bit signed integers.

Output

For each test case output the number of eliminated blocks.

Sample Input

2
3 2
Y=1,Z=3
X=3,Y=1
10 2
X=3,Y=3
Y=3,Z=3

Sample Output

5
19

Source

2010 Asia Hangzhou Regional Contest

题意:每次对立方体切割一条线上的块,问切割了多少个。

思路:暴力。。。把每个小立方块哈希编号为x*n*n+y*n+z,然后最后排序判重下就好。。。。。

stl大法好。。直接用unique。。。

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-9;
const double pi=acos(-1.0);
const int INF=0x3f3f3f3f;
const LL inf=(((LL)1)<<61)+5;
vector<int>ans;
int main()
{
    int n,m,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        getchar();
        ans.clear();
        while(m--)
        {
            char c1,c2;
            int a,b;
            scanf("%c=%d,%c=%d",&c1,&a,&c2,&b);
            getchar();
            if(c1=='X')
            {
                if(c2=='Y')
                    for(int i=1;i<=n;i++)
                        ans.pb(a*n*n+b*n+i);
                else
                    for(int i=1;i<=n;i++)
                        ans.pb(a*n*n+i*n+b);
            }
            else if(c1=='Y')
            {
                if(c2=='X')
                    for(int i=1;i<=n;i++)
                        ans.pb(b*n*n+a*n+i);
                else
                    for(int i=1;i<=n;i++)
                        ans.pb(i*n*n+a*n+b);
            }
            else
            {
                if(c2=='X')
                    for(int i=1;i<=n;i++)
                        ans.pb(b*n*n+i*n+a);
                else
                    for(int i=1;i<=n;i++)
                        ans.pb(i*n*n+b*n+a);
            }
        }
        sort(ans.begin(),ans.end());
        int sz=unique(ans.begin(),ans.end())-ans.begin();
        printf("%d\n",sz);
    }
    return 0;
}
时间: 2024-10-14 10:55:24

hdu3682 To Be an Dream Architect的相关文章

hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥

C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3682 Appoint description:  System Crawler  (2014-11-09) Description The “dream architect” is the key role in a team o

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

[水+思路] 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 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,

Lucid Dream

Lucid Dream 作者:Lo Stigmergy链接:https://www.zhihu.com/question/21260829/answer/35733194 清醒状态下时意识和潜意识基本统一,以应对与真实世界的交流.意识为主导,潜意识深藏于表层之下辅助意识.睡梦中主导逻辑判断的意识功能被抑制,情感活动更加活跃,潜意识浮上表层.如同从熟悉的模糊剪影中矗立起来的摩天城堡,潜意识构建出整个梦境世界,供弱化的意识如同真实世界一般与之交流.清醒梦的大脑活动模式介于清醒与睡梦之间,同时拥有两者

POJ2411(Mondriaan&#39;s Dream)

题目链接:传送门 题目大意:用1*2大小的砖块去铺满n*m大小的地面,有多少种方案 题目思路:因为1<=n,m<=11,并且砖块是1*2,故可以用二进制思想,也就是状态压缩DP,其中矩阵中为0的元素表示当前位置竖着放一块砖,而连着 两个1表示横着放一块砖(状态压缩真的很奇妙) #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <

poj 2411 Mondriaan&#39;s Dream(状压DP)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12232   Accepted: 7142 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

POJ 2411 Mondriaan&#39;s Dream

题目链接:http://poj.org/problem?id=2411 状态压缩Dynamic Programming. For each row, at ith position, 1 means that there is a block placed at this row and next row (vertically). otherwise, its 0. For the example in question, the state of For the example in que

【poj2411】 Mondriaan&#39;s Dream

http://poj.org/problem?id=2411 (题目链接) 题意 一个$n*m$的网格,用$1*2$的方块填满有多少种方案. Solution 轮廓线dp板子.按格dp,对上方和左方的格子的占用情况进行讨论转移.0表示已放置,1表示未放置. 细节 LL,滚动清空数组. 代码 // poj2411 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring>