To Be an Dream Architect
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3381 Accepted Submission(s): 1002
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:
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.
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
大体题意:
给你一个n×n×n 的正方体,告诉你m个直线,求出减掉m 个直线后,总共剪了几个点?
吐槽:
比赛时并没有做出来,光爆内存,赛后找了题解 发现一组样例还是过不了,思路还是错的!
自己还是弱的不行啊~~,,加油咯!
思路:
其实就是求这m 个线所有的交点减去 交点!
两个方法吧:
可以建立一个结构体,存下x,y,z三个数值,输入一条直线就遍历这直线所有的点,最后排序去重即可!
这样需要结构体运算符的重载!
这个题目 内存较小,如果还是担心爆内存的话,可以给每一个点进行编号,
每个点 编号可以是x*n *n + y *n + z 这样编号的话, 就独一无二了!~(很巧妙!)
这样也比结构体快了不少,也省了许多许多内存= =!
详细见代码:
结构体:
编号版:
大体题意:
给你一个n×n×n 的正方体,告诉你m个直线,求出减掉m 个直线后,总共剪了几个点?
吐槽:
比赛时并没有做出来,光爆内存,赛后找了题解 发现一组样例还是过不了,思路还是错的!
自己还是弱的不行啊~~,,加油咯!
思路:
其实就是求这m 个线所有的交点减去 交点!
两个方法吧:
可以建立一个结构体,存下x,y,z三个数值,输入一条直线就遍历这直线所有的点,最后排序去重即可!
这样需要结构体运算符的重载!
这个题目 内存较小,如果还是担心爆内存的话,可以给每一个点进行编号,
每个点 编号可以是x*n *n + y *n + z 这样编号的话, 就独一无二了!~(很巧妙!)
这样也比结构体快了不少,也省了许多许多内存= =!
详细见代码:
结构体:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct Node{
int x,y,z;
Node(int x = 0,int y = 0,int z = 0): x(x),y(y),z(z){}
void read(int xx,int yy,int zz){
x = xx; y = yy; z = zz;
}
bool operator < (const Node & rhs) const {
return x < rhs.x || (x == rhs.x && y < rhs.y) || (x == rhs.x && y == rhs.y && z < rhs.z);
}
bool operator == (const Node & rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z;
}
};
vector<Node> v;
int main(){
int T;
scanf("%d",&T);
while(T--){
v.clear();
int n,m;
scanf("%d %d",&n,&m);
for (int i = 0; i < m; ++i){
getchar();
char ch1,ch2;
int v1,v2;
scanf("%c=%d,%c=%d",&ch1,&v1,&ch2,&v2);
if (ch2 < ch1)swap(ch1,ch2);
if (ch1 == 'X' && ch2 == 'Y'){
for (int j = 1; j <= n; ++j){
v.push_back(Node(v1,v2,j));
}
}
else if (ch1 == 'X' && ch2 == 'Z'){
for (int j = 1; j <= n; ++j){
v.push_back(Node(v1,j,v2));
}
}
else {
for (int j = 1; j <= n; ++j){
v.push_back(Node(j,v1,v2));
}
}
}
sort(v.begin(),v.end());
int p = unique(v.begin(),v.end()) - v.begin();
printf("%d\n",p);
}
return 0;
}
编号版:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v;
int main(){
int T;
scanf("%d",&T);
while(T--){
v.clear();
int n,m;
scanf("%d %d",&n,&m);
for (int i = 0; i < m; ++i){
getchar();
char ch1,ch2;
int v1,v2;
scanf("%c=%d,%c=%d",&ch1,&v1,&ch2,&v2);
if (ch2 < ch1)swap(ch1,ch2),swap(v1,v2);
if (ch1 == 'X' && ch2 == 'Y'){
for (int j = 1; j <= n; ++j){
v.push_back(v1*n*n+v2*n+j);
}
}
else if (ch1 == 'X' && ch2 == 'Z'){
for (int j = 1; j <= n; ++j){
v.push_back(v1*n*n+j*n+v2);
}
}
else {
for (int j = 1; j <= n; ++j){
v.push_back(j*n*n+v1*n+v2);
}
}
}
sort(v.begin(),v.end());
int p = unique(v.begin(),v.end()) - v.begin();
printf("%d\n",p);
}
return 0;
}