英文题面不怎么友好,大家还是自行通过紫书了解题面吧。。。

解题思路:

  1. 面对500 ^ 3的数据范围,我们需要先用离散化解决掉爆空间的问题。

  2. 由于我们要求的总体积包括内空部分的体积,我们可以用flood_fill来解决。

注意事项:(几个细节问题)

  1. unique函数的正确使用姿势:如果是从一开始存数,注意最后要多减去1.

  2. 染色时每个三维坐标上的点代表一个长方形,所以右端点不能染色。

    3. 可以用结构体封装一下各个操作。

AC代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cstdio>
#include <cstdlib> using namespace std; const int dx[] = {, -, , , , };
const int dy[] = {, , , -, , };
const int dz[] = {, , , , , -}; int T, n, v, s;
int x1[], y1[], z1[], x0[], y0[], z0[]; int nx = , ny = , nz= ;
int lx[], ly[], lz[];
int color[][][]; struct cell{
int x, y, z; cell(int x = , int y = , int z = ): x(x), y(y), z(z) {} void setvis() const { color[x][y][z] = ; } bool getvis() const { return color[x][y][z] == ; } bool issolid() const { return color[x][y][z] == ; } bool invalid() const {
if (x <= || y <= || z <= || x >= nx || y >= ny || z >= nz ) return true;
return false;
} int area(int dir) const {
if (dx[dir] != ) return (ly[y + ] - ly[y]) * (lz[z + ] - lz[z]);
else if (dy[dir] != ) return (lx[x + ] - lx[x]) * (lz[z + ] - lz[z]);
return (lx[x + ] - lx[x]) * (ly[y + ] - ly[y]);
} int volume() const { return (lx[x + ] - lx[x]) * (ly[y + ] - ly[y]) * (lz[z + ] - lz[z]); } }; int read()
{
int x = ;
int k = ;
char c = getchar(); while (c > '' || c < '')
if (c == '-') k = -, c = getchar();
else c = getchar();
while (c >= '' && c <= '')
x = x * + c - '',
c = getchar(); return k * x;
} void discretization(int* x, int& l)
{
sort(x + , x + l + );
l = unique(x + , x + l + ) - x - ;
} int get_ID(int *x, int l, int k)
{
return lower_bound(x + , x + l + , k) - x;
} void flood_fill()
{
cell c(, , );
c.setvis();
queue<cell> q;
q.push(c);
while (!q.empty())
{
cell c = q.front();
q.pop();
v += c.volume();
for (int i = ; i < ; ++i)
{
cell c2(c.x + dx[i], c.y + dy[i], c.z + dz[i]);
if (c2.invalid()) continue;
if (c2.issolid()) s += c2.area(i);
else if (!c2.getvis())
{
c2.setvis();
q.push(c2);
}
}
}
v = * * - v;
} int main()
{
T = read();
while (T--)
{
v = , s = ;
memset(color, , sizeof(color));
n = read();
lx[] = ly[] = lz[] = ;
lx[] = ly[] = lz[] = ;
nx = ny = nz = ;
for (int i = ; i <= n; ++i)
x0[i] = read(),
y0[i] = read(),
z0[i] = read(),
x1[i] = read(),
y1[i] = read(),
z1[i] = read(),
lx[++nx] = x0[i],
lx[++nx] = x0[i] + x1[i],
ly[++ny] = y0[i],
ly[++ny] = y0[i] + y1[i],
lz[++nz] = z0[i],
lz[++nz] = z0[i] + z1[i]; discretization(lx, nx);
discretization(ly, ny);
discretization(lz, nz); for (int t = ; t <= n; ++t)
{
int sx = get_ID(lx, nx, x0[t]);
int ex = get_ID(lx, nx, x0[t] + x1[t]);
int sy = get_ID(ly, ny, y0[t]);
int ey = get_ID(ly, ny, y0[t] + y1[t]);
int sz = get_ID(lz, nz, z0[t]);
int ez = get_ID(lz, nz, z0[t] + z1[t]);
for (int i = sx; i < ex; ++i)
for (int j = sy; j < ey; ++j)
for (int l = sz; l < ez; ++l)
color[i][j][l] = ;
} flood_fill(); printf("%d %d\n", s, v);
}
}

UVa 12171 题解的更多相关文章

  1. Uva 12171 Sculpture - 离散化 + floodfill

    题目连接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  2. UVA 12171 Sculpture

    https://vjudge.net/problem/UVA-12171 题目 某人设计雕塑,用的是很扯的方法:把一堆长方体拼起来.给出长方体的坐标和长宽高,求外表面积.因为要将这雕塑进行酸洗,需要知 ...

  3. hdu 2771(uva 12171) Sculpture bfs+离散化

    题意: 给出一些边平行于坐标轴的长方体,这些长方体可能相交.也可能相互嵌套.这些长方体形成了一个雕塑,求这个雕塑的整体积和表面积. 题解: 最easy想到直接进行bfs或者dfs统计,但此题的麻烦之处 ...

  4. UVA 10131题解

    第一次写动态规划的代码,整了一天,终于AC. 题目: Question 1: Is Bigger Smarter? The Problem Some people think that the big ...

  5. 位运算基础(Uva 1590,Uva 509题解)

    逻辑运算 规则 符号 与 只有1 and 1 = 1,其他均为0 & 或 只有0 or 0 = 0,其他均为1 | 非 也就是取反 ~ 异或 相异为1相同为0 ^ 同或 相同为1相异为0,c中 ...

  6. 【OI】计算分子量 Molar mass UVa 1586 题解

    题目:(由于UVa注册不了,还是用vjudge) https://vjudge.net/problem/UVA-1586 详细说明放在了注释里面.原创. 破题点在于对于一个元素的组合(元素+个数),只 ...

  7. UVa 12171 (离散化 floodfill) Sculpture

    题意: 三维空间中有n个长方体组成的雕塑,求表面积和体积. 分析: 我们可以在最外边加一圈“空气”,然后求空气的连通块的体积,最后用总体积减去即是雕塑的体积. 还有一个很“严重”的问题就是5003所占 ...

  8. uva 12171 hdu 1771 Sculpture

    //这题从十一点开始写了四十分钟 然后查错一小时+ 要吐了 这题题意是给很多矩形的左下角(x,y,z最小的那个角)和三边的长(不是x,y,z最大的那个角T-T),为组成图形的面积与表面积(包在内部的之 ...

  9. UVA 12171 (hdu 2771)sculptrue(离散化)

    以前对离散化的理解不够,所以把端点和区间区分来考虑但是做完这题以后有了新的认识: 先来看一个问题:给你以下的网格,你需要多少空间去存储红点区间的信息呢? 只需要图上所示的1,2,3,4个点就足够表示红 ...

随机推荐

  1. Linux新硬盘、分区、格式化、自动挂载

    1.给硬盘分区 fdisk /dev/sdaCommand (m for help): nCommand actione extendedp primary partition (1-4)输入:ePa ...

  2. CSS样式之操作属性二

    ********css样式之属性操作******** 一.文本属性 1.text-align:cnter 文本居中 2.line heigth 垂直居中 :行高,和高度对应 3.vertical-al ...

  3. yii2.0下,JqPaginator与load实现无刷新翻页

    JqPaginator下载地址http://jqpaginator.keenwon.com/ 控制器部分: <?php namespace backend\controllers; use co ...

  4. Netty(1-2)Discard Client

    一.DiscardClientHandler import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelFuture; import ...

  5. angular4和asp.net core 2 web api

    angular4和asp.net core 2 web api 这是一篇学习笔记. angular 5 正式版都快出了, 不过主要是性能升级. 我认为angular 4还是很适合企业的, 就像.net ...

  6. Android Bitmap(位图)详解

    一.背景 在Android开发中,任何一个APP都离不开图片的加载和显示问题.这里的图片来源分为三种:项目图片资源文件(一般为res/drawable目录下的图片文件).手机本地图片文件.网络图片资源 ...

  7. redis启动内存不足

    redis-server.exe redis.windows.conf  --maxheap 2gb

  8. JSON(未完待续,等讲到对象时再加)

    1 定义 JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 JSON 独立于语言:JSON 使用 Jav ...

  9. springboot使用过滤器和拦截器

    1.Filter过滤器 @Componentpublic class AuthFilter implements Filter { private static final Log log = Log ...

  10. 在使用seek()函数时,有时候会报错为 “io.UnsupportedOperation: can't do nonzero cur-relative seeks”,代码如下:

    __author__ = 'ZHHT' #!/usr/bin/env python # -*- coding:utf-8 -*- import os f = open("test1" ...