2995-Image is Everuthing
来源:互联网 发布:咖啡豆知乎 编辑:程序博客网 时间:2024/06/03 19:25
参考刘汝佳算法竞赛入门经典指南~~~13页
题意:有个n*n*n的立方体,第一行输入n。。。然后一下n行依次是该立方体的 前、左、后、右、上、下。视图。。在不同视图中,每个字母代表一种颜色,“.”代表空。求最大可能存在的方格数目。
(https://icpcarchive.ecs.baylor.edu/index.PHP?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996)
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define FOR(i, n) for (int i=0; i<n; i++) const int N = 11; int n; char cube[6][N][N]; char pos[N][N][N]; //删除一整排的点 void del(int c, int x, int y) { if (c == 0) FOR(i, n) pos[y][i][x] = '.' ; else if (c == 1) FOR(j, n) pos[j][n-1-y][x] = '.' ; else FOR(k, n) pos[y][n-1-x][k] = '.' ; } //x y z 为返回的一个坐标 void get(int k, int i, int j, int len, int &x, int &y, int &z) { if (k == 0) {x = j; y = len; z = i;} if (k == 1) {x = len; y = n-1-j; z = i;} if (k == 2) {x = n-1-j; y = n-1-len; z = i;} if (k == 3) {x = n-1-len; y = j; z = i;} if (k == 4) {x = j; y = n-1-i; z = len;} if (k == 5) {x = j; y = i; z = n-1-len;} } int main() { while (scanf("%d", &n), n) { getchar(); memset(pos, '#', sizeof(pos)); FOR(i, n) { FOR(j, 6) { FOR(k, n) { char tmp = getchar(); if (tmp == '.' && (j==0||j==1||j==4)) { del(j, i, k); } cube[j][i][k] = tmp; } getchar(); } } for (;;) { bool done = true ; FOR(k, 6) FOR(i, n) FOR(j, n) if (cube[k][i][j] != '.') { FOR(p,n) { int x, y, z; get(k, i, j, p, x, y, z); if (pos[x][y][z] == '.') //如果此格子已经不存在,则往下遍历 continue; if (pos[x][y][z] == '#') //如果此方格存在,且没有被标记过颜色,则标记颜色 { pos[x][y][z] = cube[k][i][j]; break; } if (pos[x][y][z] == cube[k][i][j]) break ; //如果此方格被标记过,且标记颜色与目前访问的颜色相同,则跳出 //如果不是以上情况,也就是说:若此方格被标记过,但与访问标记颜色不同,则删除此方格 pos[x][y][z] = '.'; done = false ; } } if (done) break; } int num = 0; FOR(o, n) FOR(j, n) FOR(k, n) if (pos[o][j][k] != '.') num++; printf("Maximum weight: %d gram(s)\n", num); } return 0; }
0 0
- 2995-Image is Everuthing
- Image is Everuthing LA2995
- la 2995 Image is everything
- UVALive 2995 Image Is Everything
- LA 2995 Image Is Everything
- LA 2995 Image Is Everything
- LA 2995 Image Is Everything *
- UVaLive-2995 Image Is Everything
- UVALive 2995 Image Is Everything 策略问题
- UVaLive 2995 Image Is Everything 立方体成像
- LA 2995 & ZOJ2714 Image is Everything
- UVaLive 2995 Image Is Everything (贪心+模拟)
- UVA 2995 Image is Everying(模拟)
- UVALive 2995Image Is Everything 策略问题
- Image Is Everything
- Image Is Everything
- LA2995- Image Is Everything
- uva1030 Image Is Everything
- Ubuntu 安装Eclipse
- UVA 147 Dollars 完全背包
- [CUDA学习]1.CUDA了解及入门
- java基础——强软弱虚引用
- 深度相机三维重建
- 2995-Image is Everuthing
- 我的第一次博客作业
- iOS swift - swift常用的宏
- 【LeetCode】111. Minimum Depth of Binary Tree
- arkdown 语法说明 (简体中文版)
- Java设计模式----组合模式
- ES6箭头函数(Arrow Functions)
- 计算机是怎么判断OF位的值的?
- 4334-Trouble