列表

详情


NC245525. Jichang Xueshe

描述

Jichang Xueshe, the most important thing is persistence!

Jichang learned how to shoot from Feiwei, and succeeded three years later. When an arrow is shot, it can shoot through three view planes (front view, right view and top view) of a cube with side length N at the same time, and the coordinates of the view planes penetrated are the same. The unit cube (side length is 1) hit by the arrow will disappear immediately. Do you know how much volume is left in the cube after Jichang shoots the M arrow?

The three view planes of the cube are assigned coordinates in the same way. For example, the coordinates of the cube with side length of 3 and the three view planes are shown in the following figure.

输入描述

The first line is two integers N (1≤N≤100), M (0≤M≤N×N) , representing the side length of the cube and the number of times Jichangshoots. Next, there are M rows, each row contains two integers a, b (1≤a, b≤N), which are the two coordinate values of the view surface.

输出描述

Output an integer, that is, the remaining volume of the cube.

示例1

输入:

3 1
1 1

输出:

20

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(g++ 7.5.0) 解法, 执行用时: 12ms, 内存消耗: 1624K, 提交时间: 2022-10-23 09:36:36

#include<bits/stdc++.h>
using namespace std;
const int N=110;
bool g[N][N][N];
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,m;
	cin>>n>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		for(int i=1;i<=n;i++){
			g[a][b][i]=true;
			g[i][a][b]=true;
			g[a][i][b]=true;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(g[i][j][k]) cnt++;
			}
		}
	}
	cout<<n*n*n-cnt<<"\n";
	return 0;
}

Python3 解法, 执行用时: 886ms, 内存消耗: 14148K, 提交时间: 2023-03-26 09:35:43

m,n=map(int,input().split())
lst=[[[0 for i in range(m+1)]for k in range(m+1)] for j in range(m+1)]
vm=0
for i in range(n):
    a,b=map(int,input().split())
    for j in range(1,m+1):
        if lst[a][b][j]==0:
            lst[a][b][j]=1
            vm+=1
        if lst[j][a][b]==0:
            lst[j][a][b]=1
            vm+=1
        if lst[a][j][b]==0:
            lst[a][j][b]=1
            vm+=1
print(m**3-vm)

C++(clang++ 11.0.1) 解法, 执行用时: 22ms, 内存消耗: 5132K, 提交时间: 2022-11-04 16:02:23

#include <iostream>
using namespace std;
int s[110][110][110]={1};
int main()
{
	int n,m=1,ans=0;
	cin>>n>>m;
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		for(int i=1;i<=n;i++)
		{
			s[a][b][i]=s[a][i][b]=s[i][a][b]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				if(s[i][j][k]==0)
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

上一题