当前位置 : 主页 > 手机开发 > 其它 >

2019中山大学程序设计竞赛(重现赛) Clumsy Keke

来源:互联网 收集:自由互联 发布时间:2021-06-19
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 com

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(1mx,my,mz99) , 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)首先题给的这个正视图和侧视图不是真实图的正视图和侧视图,所以应该翻转一下;

 

(2)此时就暴力的枚举每个小块,如果都为1,那么就ans++;这样不会出现重复的情况;

代码如下:

 1 #include<iostream>
 2 #include<stdio.h>
 3 using namespace std;
 4 
 5 int m , n , k;
 6 int x[105][105];
 7 int y[105][105];
 8 int z[105][105];
 9 int tpx[105][105];
10 int tpy[105][105];
11 int ans = 0;
12 int main()
13 {
14     while(scanf("%d%d%d",&m,&n,&k)!=EOF)
15     {
16         ans = 0;
17         for(int i = 1 ; i <= m ; i++)
18         {
19             for(int j = 1 ; j <= n ; j++)
20             {
21                 cin>>x[i][j];
22             }
23         }
24         for(int i = 1 ; i <= n ;i++)
25         {
26             for(int j = 1 ;j <= k ;j++)
27             {
28                 cin>>y[i][j];
29             }
30         }
31         for(int i = 1 ; i <= k ; i ++)
32         {
33             for(int j = 1 ; j <= m ;j++)
34             {
35                 cin>>z[i][j];
36             }
37         }
38         
39         for(int i = 1 ; i <= n ; i++)
40         {
41             for(int j = 1 ; j <= m ;j++) 
42             {
43              tpx[i][j] = x[j][n-i+1] ;      //向左翻转
44             }
45         }
46 
47         for(int i = 1 ; i <= n ;i++)
48         {
49             for(int j = 1 ;j <= k ;j++)
50             {
51                 tpy[i][j] = y[n-i+1][j];  //上下翻转
52             }
53         }
54         for(int i = 1 ; i <= m ;i++)
55         {
56             for(int j = 1 ; j <= n ;j++)
57             {
58                 for(int l = 1 ; l <= k ;l++)
59                 {
60                     if(tpx[j][i]==1&&z[l][i]==1&&tpy[j][l]==1)
61                     {
62                         ans++;
63                     }
64                 }
65             }
66         }
67 
68         
69         
70     
71         cout<<ans<<endl;
72         
73     }
74 }
上一篇:面向对象思想
下一篇:构造函数的继承
网友评论