To Be an Dream Architect HDU - 3682

在这款3D想象力游戏中,玩家需构建一个n×n×n的立方体,并根据平行于坐标轴的线消除特定方块。游戏由Cobb设计,用于测试候选人成为梦建筑师的潜力,挑战在于计算经过多次消除后,总共消除了多少个独特的方块。

To Be an Dream Architect

 HDU - 3682 

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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath> 
#include <vector>
#include <set>
using namespace std;
const int N = 1e6 + 7;

struct A {
	int x, y, z;
	bool operator <(const A &a) {
		if (x == a.x) {
			if (y == a.y) return z < a.z;
			return y < a.y;
		}
		return x < a.x;
	}
	bool operator ==(const A &a) {
		if (x == a.x && y == a.y && z == a.z) return true;
		return false;
	}
}c[N];

int main() {
	
	int t;
	scanf ("%d", &t);
	while (t--) {
		
		int n, m;
		scanf ("%d %d", &n, &m);
		char ch1, ch2;
		int a, b, cnt = -1;
		for (int i = 1; i <= m; ++i) {
			
			scanf (" %c=%d, %c=%d", &ch1, &a, &ch2, &b);
			if (ch1 == 'X') {
				if (ch2 == 'Y') {
					for (int i = 1; i <= n; ++i) {
						c[++cnt].x = a;
						c[cnt].y = b;
						c[cnt].z = i;
					}
				} else {
					for (int i = 1; i <= n; ++i) {
						c[++cnt].x = a;
						c[cnt].z = b;
						c[cnt].y = i;
					}
				}
			} else if (ch1 == 'Y') {
				if (ch2 == 'Z') {
					for (int i = 1; i <= n; ++i) {
						c[++cnt].y = a;
						c[cnt].z = b;
						c[cnt].x = i;
					}
				} else {
					for (int i = 1; i <= n; ++i) {
						c[++cnt].y = a;
						c[cnt].x = b;
						c[cnt].z = i;
					}
				}
			} else {
				if (ch2 == 'Y') {
					for (int i = 1; i <= n; ++i) {
						c[++cnt].z = a;
						c[cnt].y = b;
						c[cnt].x = i;
					}
				} else {
					for (int i = 1; i <= n; ++i) {
						c[++cnt].z = a;
						c[cnt].x = b;
						c[cnt].y = i;
					}
				}
			}
			
		}
		sort(c, c + cnt + 1);
		//for (int i = 0; i <= cnt; ++i) {
		//	printf ("x=%d y=%d z=%d\n", c[i].x, c[i].y, c[i].z);
		//}
		int sum = 1, p = 0;
		for (int i = 1; i <= cnt; ++i) {
			if (!(c[i] == c[p])) {
				++sum;
				p = i;
			}   //else printf ("debug: %d\n", i);
		}
		printf ("%d\n", sum);
		
	}
	
	
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值