UVa12171 hdu2771 UVaLive4291 Sculpture
填坑系列(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的更多相关文章
- UVA 12171 Sculpture
https://vjudge.net/problem/UVA-12171 题目 某人设计雕塑,用的是很扯的方法:把一堆长方体拼起来.给出长方体的坐标和长宽高,求外表面积.因为要将这雕塑进行酸洗,需要知 ...
- UVa 12171 (离散化 floodfill) Sculpture
题意: 三维空间中有n个长方体组成的雕塑,求表面积和体积. 分析: 我们可以在最外边加一圈“空气”,然后求空气的连通块的体积,最后用总体积减去即是雕塑的体积. 还有一个很“严重”的问题就是5003所占 ...
- uva 12171 hdu 1771 Sculpture
//这题从十一点开始写了四十分钟 然后查错一小时+ 要吐了 这题题意是给很多矩形的左下角(x,y,z最小的那个角)和三边的长(不是x,y,z最大的那个角T-T),为组成图形的面积与表面积(包在内部的之 ...
- Uva 12171 Sculpture - 离散化 + floodfill
题目连接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- hdu 2771(uva 12171) Sculpture bfs+离散化
题意: 给出一些边平行于坐标轴的长方体,这些长方体可能相交.也可能相互嵌套.这些长方体形成了一个雕塑,求这个雕塑的整体积和表面积. 题解: 最easy想到直接进行bfs或者dfs统计,但此题的麻烦之处 ...
- UVa Sculpture(离散化 floodfill)
题意: 给定n个立方体的一个顶点坐标和3边长度, 问这些立方体组成的雕塑的表面积和体积, 坐标都是整数,n最大为50, 最大为500, 边长最大也是500. 分析: 继UVa221后又一道离散 ...
- 龙之谷手游WebVR技术分享
主要面向Web前端工程师,需要一定Javascript及three.js基础:本文主要分享内容为基于three.js开发WebVR思路及碰到的问题:有兴趣的同学,欢迎跟帖讨论. 目录:一.项目体验1. ...
- 时隔一年再读到the star
The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ...
- CF733D Kostya the Sculptor[贪心 排序]
D. Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- 校省选赛第一场A题Cinema题解
今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...
- 也谈Excel导出
吐槽 Excel导出在天朝的软件大环境下,差点成为软件开发必备.俺就遇到过,所有报表不提供导出功能,就能不验收的囧事.报表能查看能打印能形成图表已经完美,实在搞不懂导出excel有个毛用,但是公司依靠 ...
- /etc/fstab一些信息
[root@shine shine]# vim /etc/fstab ## /etc/fstab# Created by anaconda on Thu May 9 13:29:35 2013## A ...
- Hadoop, Python, and NoSQL lead the pack for big data jobs
Hadoop, Python, and NoSQL lead the pack for big data jobs Rise in cloud-based analytics could incr ...
- iOS: 学习笔记, 添加一个带界面约束的控制器
1. 创建一个空iOS应用程序(Empty Application). 2. 添加加控制器类. 修改控制器类的viewDidLoad - (void)viewDidLoad { [super view ...
- smali 语法基础
dalvik字节码有两种类型,原始类型和引用类型.对象和数组是引用类型,其它都是原始类型. V void Z boolean B byte S short C char I int F ...
- LightOJ_1038 Race to 1 Again
题目链接 题意: 给一个数n, 每次操作是随机的选择一个[1,N]区间内能够被n整除的数进行除法, 然后得到一个新的n. 问n变成1时的期望操作次数. 思路: 设E[n] 为 当数为x时, 变成 1 ...
- StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全
StartSSL免费SSL证书成功申请-HTTPS让访问网站更安全 一.StartSSL个人证书登录申请 1.StartSSL官网: 1.官方首页:http://www.startssl.com/ 2 ...
- [BZOJ 1502] [NOI2005] 月下柠檬树 【Simpson积分】
题目链接: BZOJ - 1502 题目分析 这是我做的第一道 Simpson 积分的题目.Simpson 积分是一种用 (fl + 4*fmid + fr) / 6 * (r - l) 来拟合 fl ...
- Phonegap 3.0 设置APP是否全屏
Phonegap 3.0 默认是全屏,如需要取消全屏,可手动修改config, 在APP/res/xml/config.xml文件可设置preference: <?xml version='1. ...