填坑系列(p.171)

orz rjl

代码基本和rjl的一样

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> template<typename Q> Q read(Q& x) {
static char c, f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x;
return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} const int maxn = + , maxc = + ;
const int dx[] = {, -, , , , };
const int dy[] = {, , -, , , };
const int dz[] = {, , , , -, }; int n, x0[maxn], y0[maxn], z0[maxn], x1[maxn], y1[maxn], z1[maxn]; int nx, ny, nz;
int xs[maxn*], ys[maxn*], zs[maxn*];
int color[maxn*][maxn*][maxn*]; struct Cell {
int x, y, z;
Cell() {}
Cell(int x, int y, int z) : x(x), y(y), z(z) {}
bool valid() const {
return x >= && x < nx - && y >= && y < ny - && z >= && z < nz - ;
}
bool solid() const {
return color[x][y][z] == ;
}
bool getvis() const {
return color[x][y][z] == ;
}
void setvis() const {
color[x][y][z] = ;
}
int volume() const {
return (xs[x+] - xs[x]) * (ys[y+] - ys[y]) * (zs[z+] - zs[z]);
}
Cell neighbor(int dir) const {
return Cell(x + dx[dir], y + dy[dir], z + dz[dir]);
}
int area(int dir) const {
if(dx[dir]) return (ys[y+] - ys[y]) * (zs[z+] - zs[z]);
if(dy[dir]) return (xs[x+] - xs[x]) * (zs[z+] - zs[z]);
return (xs[x+] - xs[x]) * (ys[y+] - ys[y]);
}
}; void discretize(int *s, int& n) {
std::sort(s, s + n);
n = std::unique(s, s + n) - s;
} int ID(int *s, int n, int x) {
return std::lower_bound(s, s + n, x) - s;
} #include<queue>
void floodfill(int &v, int &s) {
v = , s = ;
Cell c(, , );
c.setvis();
std::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.neighbor(i);
if(!c2.valid()) continue;
if(c2.solid()) s += c.area(i);
else if(!c2.getvis()) {
c2.setvis();
q.push(c2);
}
}
}
v = maxc * maxc * maxc - v;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int T; scanf("%d", &T);
while(T--) {
nx = ny = nz = ;
xs[] = ys[] = zs[] = ;
xs[] = ys[] = zs[] = maxc;
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%d%d%d%d%d%d", &x0[i], &y0[i], &z0[i], &x1[i], &y1[i], &z1[i]);
x1[i] += x0[i]; y1[i] += y0[i]; z1[i] += z0[i];
xs[nx++] = x0[i]; xs[nx++] = x1[i];
ys[ny++] = y0[i]; ys[ny++] = y1[i];
zs[nz++] = z0[i]; zs[nz++] = z1[i];
}
discretize(xs, nx);
discretize(ys, ny);
discretize(zs, nz); memset(color, , sizeof color);
for(int i = ; i < n; i++) {
int X1 = ID(xs, nx, x0[i]), X2 = ID(xs, nx, x1[i]);
int Y1 = ID(ys, ny, y0[i]), Y2 = ID(ys, ny, y1[i]);
int Z1 = ID(zs, nz, z0[i]), Z2 = ID(zs, nz, z1[i]);
for(int X = X1; X < X2; X++) for(int Y = Y1; Y < Y2; Y++)
for(int Z = Z1; Z < Z2; Z++) color[X][Y][Z] = ;
}
int v, s;
floodfill(v, s);
printf("%d %d\n", s, v);
}
return ;
}

UVa12171 hdu2771 UVaLive4291 Sculpture的更多相关文章

  1. UVA 12171 Sculpture

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

  2. UVa 12171 (离散化 floodfill) Sculpture

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

  3. uva 12171 hdu 1771 Sculpture

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

  4. Uva 12171 Sculpture - 离散化 + floodfill

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

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

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

  6. UVa Sculpture(离散化 floodfill)

    题意: 给定n个立方体的一个顶点坐标和3边长度,  问这些立方体组成的雕塑的表面积和体积,   坐标都是整数,n最大为50,  最大为500, 边长最大也是500. 分析: 继UVa221后又一道离散 ...

  7. 龙之谷手游WebVR技术分享

    主要面向Web前端工程师,需要一定Javascript及three.js基础:本文主要分享内容为基于three.js开发WebVR思路及碰到的问题:有兴趣的同学,欢迎跟帖讨论. 目录:一.项目体验1. ...

  8. 时隔一年再读到the star

    The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ...

  9. CF733D Kostya the Sculptor[贪心 排序]

    D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

随机推荐

  1. 批量翻转PNG图片

    用了好几个软件都不好用. 要么不能翻转PNG, 要么翻转之后没有透明度了. 基本上全是图形界面, 要鼠标批量拖放. 所以, 还是自己动手, 写一个批量png翻转工具. #include <ios ...

  2. Win8 +PHP+IIS配置

    1.安装IIS:控制面板-程序和功能-打开或关闭Windows功能 2.配置PHP环境 -添加ISAPI筛选: -添加脚本映射:

  3. 配置处理结果result

    Action处理完用户请求后返回一个字符串,整个字符串就是一个逻辑视图名. 除此之外,struts2还支持多种结果映射,struts2将结果转为实际资源时,不仅可以是JSP视图资源,也可以是FreeM ...

  4. ES6-个人学习笔记二--解构赋值

    第二期,解构赋值如果能够熟练应用确实是个十分方便的功能,但是过分的依赖和嵌套只会让代码理解和维护起来十分困难,是个体现高逼格的表达式呢~ 1,解构赋值的基础 //定义:es6运行按照一定模式,从数组或 ...

  5. andriod 开发记录apidemos 错误解决

    android sdk 里面有simple 文件夹里面有对应的demo  但是拿出来esplise运行报错 解决方案如下 右键错误代码goto,给对应错误的单引号前加 \ 原文http://stack ...

  6. WPF 分页控件 WPF 多线程 BackgroundWorker

    WPF 分页控件 WPF 多线程 BackgroundWorker 大家好,好久没有发表一篇像样的博客了,最近的开发实在头疼,很多东西无从下口,需求没完没了,更要命的是公司的开发从来不走正规流程啊, ...

  7. HTML5之一HTML5简介

    1.什么是HTML5? HTML5是HTML的新一代标准.以前版本的HTML标准4.01发布于1999. 自1999年以后,web已经有了翻天覆地的变化. 实际上HTML5仍旧是开发中的一个标准.但是 ...

  8. 根据http协议传送数据

    发送的内容: [50 4f 53 54 20 2f 64 65 78 2f 66 69 72 65 70 6f 77 65 72 20 48 54 54 50 2f 31 2e 31 0d 0a 43 ...

  9. MFC窗口分割以及各窗口间的通讯

    一个偶然的机会又重新接触了MFC窗口的分割,自己结合资料重新写了一个窗口分割的程序,现将具体流程跟大家分享一下: 1.我们先创建一个MFC单文档类的程序,具体分割方式先将单文档整个客户区分成两行一列, ...

  10. solrnet - document

      Overview and basic usage Mapping Initialization Create/Update/Delete Querying Faceting Highlightin ...