Thinking CSU1697 Surface Area of ​​Cubes

Portal: Click to open the link

Title: Give a cuboid with side lengths A, B, and C. Then give n spatial positions, which means to dig a small cube with side length 1 at this position. Find the surface area of ​​this three-dimensional figure after digging n positions.

Thinking: It looks very complicated, but it is very, very simple when you think about it carefully.

First of all, for a small cube, there are 6 faces, we first consider the two opposite faces.

In an opposing face, if there are entities on both sides, then the surface area will be +2 after digging out the small cube

In an opposing face, only one side has entities , Then the surface area will not change after digging out this small cube

In an opposing surface, both sides have been dug away, then the surface area will be -2 after digging out this small cube
< /p>

So, I just need to discuss whether a certain position is vacant. Obviously, it can be maintained with set.

So this question is basically solved.

#include#include#include# include#include#include#include#include#include#include#include#include#include# include#include#define fuck(x) cout<<"["<S;bool check(int x, int y, int z) {if(x <1 || x> A || y <1 || y> B || z <1 || z> C) return false; if(S.count(Node(x, y, z))) return false; return true;)int f(int x) {if(x == 0) return -2; if(x == 1) return 0; return 2;} int main() {int n; //FIN; while(~scanf("%lld%lld%lld%d", &A, &B, &C, &n)) {LL ans = 2 * A * B + 2 * A * C + 2 * B * C; S.clear(); for(int i = 1; i <= n; i++) {int x, y, z; scanf("%d% d%d", &x, &y, &z); x++; y++; z++; ans += f(check(x-1, y, z) + check(x + 1, y, z)); ans += f (check(x, y-1, z) + check(x, y + 1, z)); ans += f(check(x, y, z-1) + check(x, y, z + 1) ); S.insert(Node(x, y, z));} printf("%lld
", ans);} return 0;} 

Leave a Comment

Your email address will not be published.