H - Clumsy Keke (HDU - 6518) 暴力枚举 SDUT新生挑战赛(笨手笨脚的小新)

74 篇文章 12 订阅

题目链接:传送门

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 11, and the vertices of these cubes are all on the grid. Give you three 0/1 matrices, each representing each of the three views. 00 means that there is no projection of cubes at this position of the view; 11 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)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)(1,1,1) to (mx,my,mz)(mx,my,mz)).

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

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

Following input a 0/1 matrix with mzmz lines and mxmx columns representing the top view, and the xx-th column of the zz-th row represents the projection of all the cubes of the top view such as (x,?,z)(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++;这样不会出现重复的情况;

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
const int N = 5e6 + 10;
using namespace std;

int zheng[111][111];
int ce[111][111];
int fu[111][111];
//int ti[111][111][111];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,y,z;
    while(cin>>x>>y>>z)
    {
        int i,j;
        for(i=1; i<=x; i++)
        {
            for(j=1; j<=y; j++)
                cin>>zheng[i][j];
        }
        for(i=1; i<=y; i++)
        {
            for(j=1; j<=z; j++)
                cin>>ce[i][j];
        }
        for(i=1; i<=z; i++)
        {
            for(j=1; j<=x; j++)
                cin>>fu[i][j];
        }
        int k;
        int cnt=0;
        for(i=1; i<=x; i++)
        {
            for(j=1; j<=y; j++)
            {
                for(k=1; k<=z; k++)
                {
                    if(zheng[i][j]&&ce[j][k]&&fu[k][i])
                    {
                        cnt++;
                    }
//                    printf("%d %d %d\n",i,j,k);
//                    printf("%d %d %d\n\n",zheng[i][j],ce[j][k],fu[k][i]);
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

法二:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
const int N = 5e6 + 10;
using namespace std;

//int zheng[111][111];
//int ce[111][111];
//int fu[111][111];
int ti[111][111][111];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x,y,z;
    while(cin>>x>>y>>z)
    {
        int i,j,k;
        for(i=1; i<=x; i++)
            for(j=1; j<=y; j++)
                for(k=1; k<=z; k++)
                    ti[i][j][k]=1;
        for(i=1; i<=x; i++)
        {
            for(j=1; j<=y; j++)
            {
                int kk;
                cin>>kk;
                if(!kk)
                    for(int k=1; k<=z; k++)
                        ti[i][j][k]=0;
            }
        }
        for(i=1; i<=y; i++)
        {
            for(j=1; j<=z; j++)
            {
                int kk;
                cin>>kk;
                if(!kk)
                    for(int k=1; k<=x; k++)
                        ti[k][i][j]=0;
            }
        }
        for(i=1; i<=z; i++)
        {
            for(j=1; j<=x; j++)
            {
                int kk;
                cin>>kk;
                if(!kk)
                    for(int k=1; k<=y; k++)
                        ti[j][k][i]=0;
            }
        }
        int cnt=0;
        for(i=1; i<=x; i++)
        {
            for(j=1; j<=y; j++)
            {
                for(k=1; k<=z; k++)
                {
                    if(ti[i][j][k])
                        cnt+=ti[i][j][k];
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

C语言代码:

法一:

#include <stdio.h>
#include <stdlib.h>
#define N 111

int zheng[N][N];
int ce[N][N];
int fu[N][N];

int main()
{
    int x,y,z;
    while(~scanf("%d%d%d",&x,&y,&z))
    {
        int i;
        int j;
        // 输入视图
        for(i=1;i<=x;i++)
        {
            for(j=1;j<=y;j++)
            {
                scanf("%d",&zheng[i][j]);
            }
        }
        // 输入侧视图
        for(i=1;i<=y;i++)
        {
            for(j=1;j<=z;j++)
            {
                scanf("%d",&ce[i][j]);
            }
        }
        //输入俯视图
        for(i=1;i<=z;i++)
        {
            for(j=1;j<=x;j++)
            {
                scanf("%d",&fu[i][j]);
            }
        }

        int k;
        int cnt=0;
        for(i=1;i<=x;i++)
        {
            for(j=1;j<=y;j++)
            {
                for(k=1;k<=z;k++)
                {
                    if(zheng[i][j]&&ce[j][k]&&fu[k][i])
                    {
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值