POJ 3792 Area of Polycubes(模拟)
来源:互联网 发布:阿里云服务器怎么降配 编辑:程序博客网 时间:2024/05/29 23:23
POJ 3792
大意:
按顺序给你一堆正方体,如果当前输入的正方体上下左右前后都没有跟之前的正方体有连接,就输出NO,并输出当前是第几个。如多每次输入的正方体跟之前的都有连接,那么最后输出组成的几何体的表面积。
思路:一步一步模拟就行。注意:1.要判一下有重复的输入,如果有重复的输入,要输出NO,并输出第几。。2.注意下标不要向下溢出。
#include <stdio.h>#include <algorithm>#include <vector>#include <string.h>#define max(a, b) ((a)>(b)?(a):(b))using namespace std;int T;int n;bool vis[110][110][110];struct node{ int x, y, z;} P[1010];void Solve(){ scanf("%d", &T); for(int tt = 1; tt <= T; ++tt) { memset(vis, false, sizeof(vis)); scanf("%d", &n); printf("%d ", tt); scanf("%d,%d,%d", &P[1].x, &P[1].y, &P[1].z); P[1].x++; P[1].y++; P[1].z++; vis[P[1].x][P[1].y][P[1].z] = true; bool flag = true; for(int i = 2; i <= n; ++i) { scanf("%d,%d,%d", &P[i].x, &P[i].y, &P[i].z); P[i].x++; P[i].y++; P[i].z++; if(vis[P[i].x][P[i].y][P[i].z] == true) { if(flag) { printf("NO %d\n", i); flag = false; } continue; } vis[P[i].x][P[i].y][P[i].z] = true; if(!(vis[P[i].x-1][P[i].y][P[i].z] || vis[P[i].x+1][P[i].y][P[i].z] || vis[P[i].x][P[i].y-1][P[i].z] || vis[P[i].x][P[i].y+1][P[i].z] || vis[P[i].x][P[i].y][P[i].z-1] || vis[P[i].x][P[i].y][P[i].z+1])) { if(flag) { printf("NO %d\n", i); flag = false; } } } if(flag) { int sum =n*6; for(int i = 1; i <= n; ++i) { if(vis[P[i].x-1][P[i].y][P[i].z]) { sum -= 1; } if(vis[P[i].x+1][P[i].y][P[i].z]) { sum -= 1; } if(vis[P[i].x][P[i].y-1][P[i].z]) { sum -= 1; } if(vis[P[i].x][P[i].y+1][P[i].z]) { sum -= 1; } if(vis[P[i].x][P[i].y][P[i].z-1]) { sum -= 1; } if(vis[P[i].x][P[i].y][P[i].z+1]) { sum -= 1; } } printf("%d\n", sum); } }}int main(){ ///freopen("data.in", "r", stdin); ///freopen("data.out", "w", stdout); Solve(); return 0;}
0 0
- POJ 3792 Area of Polycubes(模拟)
- Area of Polycubes poj 3792
- POJ 3792 Area of Polycubes 解题报告
- Area of Polycubes(简单模拟)
- POJ 3792 Area of Polycubes 已被翻译
- Sicily 1629. Area of Polycubes
- liveoj 4238 - Area of Polycubes(搜索)
- 南邮 OJ 1537 G ? Area of Polycubes
- Area of Polycubes 使搜索清晰而简化
- poj 1389 Area of Simple Polygons
- poj 1389 Area of Simple Polygons
- POJ-1389-Area of Simple Polygons
- poj 1389 Area of Simple Polygons
- POJ 1389 Area of Simple Polygons
- POJ 1389 Area of Simple Polygons .
- POJ 1389 Area of Simple Polygons 笔记
- POJ 2043 Area of Polygons 笔记
- poj 1389 Area of Simple Polygons(线段树做法)
- php动态网页实现页面静态化 通过在初次被访问时生成html文件保存起来,下次该PHP程序被访问时就直接找到以前被访问过的html页面
- Python中map()函数浅析
- 对于IP地址检测问题的考虑!
- 关于RichEdit控件的一些资料
- C#-format-删除字符串---ShinePans
- POJ 3792 Area of Polycubes(模拟)
- java23种设计模式的有趣解释
- 数据库连接 什么是长短连接??
- JAVA编程思想学习第一篇の对象导论
- 使用kingEditor实现图片上传
- Android设计模式——模板方法模式
- sed 用法
- java 学习之Eclipse使用
- 关于PHP程序使用file_get_content()函数进行抓取PHP程序与smarty结合编译过程中产生的静态文件,抓取不了?连接超时?(地址映射)