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

解题思路:

  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. 洛谷 P1070 道路游戏(noip 2009 普及组 第四题)

    题目描述 小新正在玩一个简单的电脑游戏. 游戏中有一条环形马路,马路上有 nn个机器人工厂,两个相邻机器人工厂之间由一小段马路连接.小新以某个机器人工厂为起点,按顺时针顺序依次将这 nn个机器人工厂编 ...

  2. MySQL server has gone away和Maximum execution time of 120 seconds exceeded

    今天在写采集时碰到两个问题1.MySQL server has gone away2.Maximum execution time of 120 seconds exceeded 采集程序写好运行大概 ...

  3. beanshell解析json(从简单到复杂)

    使用beanshell 解析单层Json: Json 数据如下: { "status":200, "code": 0, "message": ...

  4. window.addeventlistener使用方法

    http://www.jb51.net/article/49858.htm .................................................... (要注意的是div ...

  5. 【手撸一个ORM】第四步、Expression(表达式目录树)扩展

    到这里,Orm的基架已经搭起来了,接下来就是激动人心的部分,表达式目录树转Sql语句,SqlDataReader转数据实体等等,但是在这之前,我们需要扩展下表达式目录树的方法,以方便后面的相关操作. ...

  6. B - Median Pyramid Easy 构造题

    B - Median Pyramid Easy Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statemen ...

  7. Eclipse - 安装语言包

    Open the install wizard with 'Help' > 'Install new software...' add the Babel p2 repository: http ...

  8. WPF (VisualChildren)可视化子元素详解

    VisualChildrenCount    的 FrameworkElement 实现始终返回 0 或 1.  如果类所要维护的可视化子元素集合的成员数可能超过 1,则这样的类必须重写此属性和 Ge ...

  9. 记录:swift学习笔记1-2

    swift还在不断的更新做细微的调整,都说早起的鸟儿有虫吃,那么我们早点出发吧,趁着国内绝大多数的coder们还没有开始大范围普遍应用. 网上有些大神说:swift很简单!我不同意这个观点,假如你用h ...

  10. check设置默认值但刷新后就会清空

    关于check设置默认值但刷新后就会清空的问题 可能是由于浏览器的问题 我这边就直接在ComponentDidMount里面加jq使得该radio的状态为选中,后边还发现一个问题就是在点击的时候多次点 ...