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

解题思路:

  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. InstelliJ IDEA使用js+servlet+ajax入门

    对于Ajax,我们先了解三点(完整的JS代码在后面) 一.Ajax的出现对javascript的影响. Ajax是微软提出的一种允许客户端脚本发送HTTP请求的技术(XMLHTTP),拯救了大多数ja ...

  2. 黑马旅游网案例 Bug集锦

  3. c# Array或List有个很实用的ForEach方法,可以直接传入一个方法对集合中元素操作

    using System; using System.Collections.Generic; namespace demo { class Program { static void Main(st ...

  4. 牛客小白月赛13 G(双向搜索)

    AC通道 两边同步搜,一步里面A走一次B走两次,遇到对方走过的地方就得到了答案. #include <bits/stdc++.h> using namespace std; const i ...

  5. Java EE学习笔记(八)

    动态SQL 1.动态SQL中的元素 1).作用:无需手动拼装SQL,MyBatis已提供的对SQL语句动态组装的功能,使得数据库开发效率大大提高! 2).动态SQL是MyBatis的强大特性之一,My ...

  6. Java VisualVM添加Visual GC插件

    1.访问地址:https://visualvm.github.io/pluginscenters.html,找到自己JDK版本对应的插件下载地址(我的JDK版本为1.7.0_67): 2.点击该链接进 ...

  7. 举例实用详解sc.textFile()和wholeTextFiles()

    谈清楚区别,说明白道理,从案例开始: 1 数据准备 用hdfs存放数据,且结合的hue上传准备的数据,我的hue截图: 每个文件下的数据: 以上是3个文件的数据,每一行用英文下的空格隔开: 2 测试 ...

  8. Aspose.word组件介绍

    阅读目录 1.基本介绍 2.文档对象模型概述        本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html 本博客其他.NET开 ...

  9. ABAP事件的简单用法

    1.1.事件: 用于捕获某类对象状态的改变来触发事件的方法,并进行处理 1.2.定义:可以在类或接口中进行声明 EVENTS|CLASS-EVENTS evt  EXPORTING … VALUE(p ...

  10. Hbase region查找过程

    HBase的table是该region切分的,client操作一个row的时候,如何知道这个row对应的region是在哪台Region server上呢?这里有个region location过程. ...