1. 程式人生 > >2019中山大學程序設計競賽(重現賽) Clumsy Keke

2019中山大學程序設計競賽(重現賽) Clumsy Keke

muti coord main spa current oss ima ins rip

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 }

2019中山大學程序設計競賽(重現賽) Clumsy Keke