当前位置:网站首页>Battle plague Cup -- strange shape
Battle plague Cup -- strange shape
2022-07-28 06:39:00 【Step by step b】
Xiao Fan has one with a side length of 2 Square white paper , It's painted 2×2 The length of each side is 1 Lattice of , Each grid can be placed with an edge length of 1 The cube . There are several edges in Xiao Fan's hand, the length of which is 1 The cube , He randomly placed some cubes on each grid , Find the surface area of the geometry composed of these cubes .

Input format :
Enter two lines , Two per line, no more than 100 The positive integer , Stands for looking down at , The number of cubes on each grid drawn on white paper .
Output format :
Output one line , Contains an integer , Represents the surface area of the geometry .
sample input :
The input data corresponding to the above figure is as follows :
2 1
1 1
sample output :
20
The code is as follows :
#include<iostream>
using namespace std;
int main() {
int a[5];
cin>>a[1]>>a[2]>>a[3]>>a[4];
int sum = 0;
sum = (a[1]+a[2]+a[3]+a[4])*6 - 8;// Because it is a positive integer , Therefore, there are at least 4 Square , Each adjacent one is reduced by two faces ,4 Two adjacent , So reduce 8 Face to face , So subtract 8
for (int i = 1; i < 5; i++) {
if (a[i] > 1) sum -= 2*(a[i]-1);
}// Every additional layer , Contact with the bottom layer , So reduce 2 Face to face
int max = (a[1]>a[2])?a[1]:a[2];// If input 4 3 1 2, Then the top layer is not equal , But the middle layer has equal , So we should judge by circulation
int min = (a[1]<a[2])?a[1]:a[2];
for (;max > 1; max--) {
if (max == min) {
sum -= 2 * (max - 1);
}
}// In the first row, two squares are adjacent
max = (a[1]>a[3])?a[1]:a[3];
min = (a[1]<a[3])?a[1]:a[3];
for (;max > 1;max--) {
if (max == min) sum -= 2 * (max - 1);
}// In the first column, two squares are adjacent
max = (a[3]>a[4])?a[3]:a[4];
min = (a[3]<a[4])?a[3]:a[4];
for (;max > 1;max--) {
if (max == min) sum -= 2 * (max - 1);
}// In the second row, two squares are adjacent
max = (a[2]>a[4])?a[2]:a[4];
min = (a[2]<a[4])?a[2]:a[4];
for (;max > 1;max--) {
if (max == min) sum -= 2 * (max - 1);
}// In the second column, two squares are adjacent
cout<<sum;
}
min) sum -= 2 * (max - 1);
}// In the second column, two squares are adjacent
cout<<sum;
}
边栏推荐
猜你喜欢

Development of clip arbitrage / brick carrying arbitrage system

Problems of font modification and line spacing in word automatic directory

Solve the problem that the memory occupation is higher than that of the application process

QT painting event - set background picture

2021-11-10

2022-05-24 use of spiel

Listener

小程序navigator无法跳转(debug)

OpenGL quick configuration method

QT implementation outputs relevant information to log file
随机推荐
QT painting event - set background picture
下雨场景效果(一)
【C语言】字符串库函数介绍及模拟
2022-06-07 ResponseBodyAdvice导致Swagger出现弹框问题
【动态规划--买卖股票的最佳时期系列】
OJ 1129 fraction matrix
2022-05-15 based on JWT token
什么气传导蓝牙耳机好、配置比较高的气传导耳机推荐
C语言的文件操作
Redhawk Dynamic Analysis
战疫杯--我的账本
开放式耳机有哪些、四款音质超好的气传导耳机推荐
量化交易机器人系统开发
当前学习进度
[队列,栈的简单应用----包装机]
[哈希表基础知识]
OJ 1089 春运
到底什么是Hash?(量化交易机器人系统开发)
刷题记录----链表
QT implementation outputs relevant information to log file