填坑系列(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. PHP设计模式之:工厂模式

    工厂模式: 由工厂类根据参数来决定创建出哪一种产品类的实例: 工厂类是指包含了一个专门用来创建其他对象的方法的类.所谓按需分配,传入参数进行选择,返回具体的类.工厂模式的最主要作用就是对象创建的封装. ...

  2. [lua]原来这才是表驱动的正确表达方式

    曾经写了个很煞笔的脚本模拟switch..case语法形式.[lua]尝试一种Case语法糖 而今实际项目应用中突发,原来这才是正确的表驱动方式表达.如下所贴: function event_do( ...

  3. TP缓存设计方案解析

    TP的缓存主要依赖Cache类,Cache类其实是一个代理类,Cache类通过getInstance静态方法来获取缓存实例,而getInstance方式实际是调用Cache类的connect方法,该方 ...

  4. 分享一个自己写的基于TP的关系模型(四)

    修复分页BUG,原有代码查询到最后一页就一只查询最后一页 $ ? $; $this->maxPage = ceil($this->total/$this->rows); //$thi ...

  5. Git (2)

    要使用Git首先遇到的问题是怎么把文件加到库中. 很简单. 新建一个目录,然后git init. 完成上述工作之后的唯一改动是在当前目录下生成了一个.git的子目录.这个子目录是一个集中的数据库,包含 ...

  6. HTML5 程序设计笔记(二)

    Canvas API 1.HTML5 Canvas 概述 1.1 历史 Canvas的概念最初是由苹果公司提出的,用于在Mac OS X WebKit中创建控制板部件(dashboard widget ...

  7. Bad owner or permissions on .ssh/config

    Bad owner or permissions on $HOME/.ssh/config The ssh with RHEL 4 is a lot more anal about security ...

  8. 常用sql笔记

    Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,score) 成绩表Teacher(T#,Tname) 教师表问题:1.查 ...

  9. 了解SOA是什么!

    面向服务架构 面向服务的体系结构(service-oriented architecture,SOA)是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的接口和契约联系起来 ...

  10. register 不允许 block 模式,而默认的是

    Exception in thread "main" java.nio.channels.IllegalBlockingModeException at java.nio.chan ...