2019中山大學程序設計競賽(重現賽) 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
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)
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 }
2019中山大學程序設計競賽(重現賽) Clumsy Keke