Clumsy Keke(模拟)

Problem Description

Keke is currently studying engineering drawing courses, and the teacher has taught her how to find its volume through the three views of the part. But her brain doesn't work well that she can't find the volume of complex parts. So she needs your help.

To simplify the problem, the part is made up of cubes with side length 1 , and the vertices of these cubes are all on the grid. Give you three 0/1 matrices, each representing each of the three views. 0 means that there is no projection of cubes at this position of the view; 1 means that there is a projection of cubes at this position of the view.

Now Keke wants you to help her find the volume of the part determined by the three views.

Input

There are mutiple test cases, the number of which is no more than 10. For each test case:

The first line of input contains three integers mx,my,mz(1≤mx,my,mz≤99) , which represent the coordinate range of all possible cubes (i.e. all possible cubes are in the cuboid area whose body diagonal is from (1,1,1) to (mx,my,mz) ).

Following input a 0/1 matrix with mx lines and my columns representing the front view, and the y -th column of the x -th row represents the projection of all the cubes in the front view such as (x,y,?) .

Following input a 0/1 matrix with my lines and mz columns representing the side view, and the z -th column of the y -th row represents the projections of all the cubes in the side view such as (?,y,z) .

Following input a 0/1 matrix with mz lines and mx columns representing the top view, and the x -th column of the z -th row represents the projection of all the cubes of the top view such as (x,?,z) .

The '? ' in the above coordinates represents any integer. Numbers in the same line are separated by spaces. For more detailed input information, please see the sample.

Output

For each test case:

The first line of output should contain an integer, representing the volume of the part determined by the three views. If the determined part is not unique, find the largest of all possible parts.

Keke's teacher promises that there is at least one part that satisfies the input.

Sample Input

 
5 6 4
1 1 1 1 1 1
0 0 0 1 0 1
0 0 0 1 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 1 1 0
1 0 0 1
0 0 0 1
0 0 0 1
0 0 0 1
1 1 1 1
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 1 1 1 1

Sample Output

 

17

因为数据中给出了该图形的三视图,若还原的立体图形中,某一位有是实体,在三视图中,该位置都出现过。

所以对某一维,当其他两维的数字为1时,该直线上所有的位置数目++,例如当俯视图时,给出x,y,若x,y

位置上的数为1,则令(x,y,∀z)++;最后统计数量为3的位置,即是实体的方块数;

#include<iostream>
using namespace std;
int a[110][110][110];//模拟x,y,z
int main(){
	int x, y, z;
	while (cin >> x >> y >> z)          //枚举时,下标依此为x,y,z;
	{
	memset(a, 0 ,sizeof a);
		int num;
		for(int i = 1; i <= x; i++)
		   for(int j = 1; j <= y; j++)
		    {
		    	cin >> num;
				if(num)
				   for(int k = 1; k <= z; k++)
				      a[i][j][k]++;     
		    }
		for(int i = 1; i <= y; i++)
		   for(int j = 1; j <= z; j++)
		    {
		    	cin >> num;
				if(num)
				   for(int k = 1; k <= x; k++)
				      a[k][i][j]++;     
		    }
		for(int i = 1; i <= z; i++)
		   for(int j = 1; j <= x; j++)
		    {
		    	cin >> num;
				if(num)
				   for(int k = 1; k <= y; k++)
				      a[j][k][i]++;     
		    }
		    int cnt = 0;
		for(int i = 1; i <= x; i++)
		   for(int j = 1; j <= y; j++)
		      for(int k = 1; k <= z; k++)
		          if(a[i][j][k] == 3)   //统计
		             cnt++;
		cout << cnt << endl;
	}
	return 0;
}
 

猜你喜欢

转载自blog.csdn.net/weixin_43731933/article/details/89425895